ObjectDb - JAVA - Error with Key

0

I get this error:

Failed to commit transaction: Attempt to reuse an existing primary key value (model.Assignatura:4)

tell me this part of the code:

 public void modificar(Assignatura ass) throws GestorException {
        //TODO codificar el metode modificar
         em.getTransaction().begin();
        em.persist(ass);
        em.getTransaction().commit();
    } 

I do not know what can be wrong .. can you help me?

    
asked by Montse Mkd 07.03.2018 в 19:30
source

1 answer

1

As you are using EntityManager managed by java container, he handles transactions. Therefore, entityManager.getTransaction () and em.getTransaction().commit(); are not necessary.

JTA initiates and confirms your transaction but if you want it to be done at the time of doing the insert use em.flush(); this equals a commit , as which is done so that the result is reflected in the database.

    
answered by 07.03.2018 / 21:06
source