Sunday 15 February 2015

java - EntityManager performs UPDATE to database automatically when I change a field of Embedded object, but do not call merge or flush -


I have some bean methods that cause unexpected updates of the database. I only select only certain fields for my needs Execute statement and recalculation values, but do not want to update it automatically. How can I control this process without interfering with default initial settings?

The log file tells about some mysterious background flush process:

  Start the unit of work flush execute the query UpdateObjectQuery ..   

I can save this update from creating em.setFlushMode (FlushModeType.COMMIT); In my method and it is really strange on my machine. It is fine - there is no update during the method execution and afterwards. But I also need to return the transaction to the client machine - only in this case I will not see any update statement in my logs. But is this treatment method right? When changing the flushmod for EM in my Bean method, will other threads auto-commits?

My Machine (Glassfish 2.0, Ubuntu 12.10, EclipseLink 3.2, JDK 1.7.0_15)

Client Machines (Glassfish 2.0, Win 7x86_64, EclipseLink 3.2, JDK 1.7.0_15)

If you want objects but do not want to keep changes, if you have JPA 2.0 or em. Using clear (), you want to separate it from EntityManager using the Entity, if you want to delete everything, use the transaction. Rolling is very similar, like clearing or closing the antimy manager. Only different entities will be changed only when you merge them back into EntityManager.

If you do not use JTDA, you can also read it out of the transaction if the EM is not connected to any transaction, the changes can not be flushed. In this way, you can use an EM which is not associated with the transaction and when it is done, leave EntityManager.

No comments:

Post a Comment