File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubts about refresh + merge function in JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Doubts about refresh + merge function in JPA" Watch "Doubts about refresh + merge function in JPA" New topic
Author

Doubts about refresh + merge function in JPA

Tom Kowalski
Ranch Hand

Joined: Feb 17, 2009
Posts: 72
Hi, I have read chapter about using EntityManager in 'EJB 3.0 in Action' and I have some doubts about one thing. The authors wrote, that a way of getting the latest data from DB is to use refresh function (Refresh the state of the instance from the database, overwriting changes made to the entity, if any.). The parameter of this function is an object, which should be already attached to the EntityManager (EM), so we could write it like this:



Earlier the authors have already wrote, that functions connected to EM (like persist, merge and so on), don't have to be done right away, they will be done later or soner, but we can't be shure when (of course before transaction commit) - it's becaouse FlashMode is set to 'Auto'. So me questions is simple. Is it possible, that in



the 'inside' part of the function (entityManager.merge(item)), will be executed by the entitymanager so that it will send to DB some kind of new data connected with this entity (it will be flushed), and later the 'refresh' method will get this new data (which will be already in DB).

And, if no, what about this code:


I hope my questions is quite clear (if not sorry). Thanks a lot for the answers.

SCJP, SCWCD, OCUP
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubts about refresh + merge function in JPA