Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Doubts about refresh + merge function in JPA

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I want my playground back. Here, I'll give you this tiny ad for it:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic