java - JPA not persisting entity -
I am trying to save database changes made in a different unit. The objective of the unit is given by the argument (designated as data):
generate private bullion (common game data data) {Boolean results = true; EntityManager em = HibernateUtil.currentEntityManager (); Try {em.getTransaction (). Start (); Em.merge (data); Em.flush (); ... some changes in the data object ... em.persist (data); Em.flush (); Committed to em.getTransaction (). } Hold (ex before) {... return false; } Back true; } As I've read that I am using a different unit, I must first merge. But after work is done successfully, I do not see any change in the database. Where's the mistake?
As you do not save a new unit (by your comment), you do No need to continue to call () . Apart from this I did not see any reason to make 'some changes' after calling merge () , so I called merge () after those changes. > Therefore, try the following: em.getTransaction (). Start (); ... some changes in the data object ... em.merge (data); Em.flush (); Committed to em.getTransaction (). Also very important: if you re-use a ThreadLocal variable with EntityManager , then you have the last transaction Kind things should be taken care of (at least clear it + maybe close it) If the bug still persists, try to recreate one unit manager.
Comments
Post a Comment