Java Web - remove method Caused by: org.hibernate.MappingException: Unknown entity: java.lang.Integer

0

Gent, and I'm trying to create a method in which I delete the database record. However, it is giving the following error:

Caused by: org.hibernate.MappingException: Unknown entity: java.lang.Integer

Code:

public void  delete(int user)  {
    Consultar consulta = new Consultar ();


    EntityManager deletar = consulta.getEntityManager();

    System.out.println("usuário deletado"+user);

        deletar.getTransaction().begin();
        deletar.remove(user);
        deletar.getTransaction().commit();
}
    
asked by anonymous 10.12.2017 / 03:35

1 answer

1

user is a variable of type int .

deletar is the name given to your EntityManager (bad name).

When you do this:

deletar.remove(user);

You are prompting EntityManager to remove an integer from the database. That does not make sense. Remove from where? Which table?

The object that you should pass to the remove method should be of type User , Usuário or something you have that has the @Entity annotation.

    
10.12.2017 / 03:54