Why does EntityManager insert instead of updating?
I have a main thread where I get an object from database, then close the EntityManager, then put the object into a queue. A worker thread makes some business with the object, then puts it into a finished queue. Then the main thread gets the object from the finished queue and merges the object: EntityManager em = entityManagerFactory.createEntityManager(); em.getTransaction().begin(); // Print the primary key ID of the object, // it is NOT empty yes it exists in the db. em.merge(myObject); em.getTransaction().commit(); em.close(); I confirm the primary key ID of the object by printing it before