aspose file tools*
The moose likes Object Relational Mapping and the fly likes Will hibernate take care of the modification done on the merged detached object ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Will hibernate take care of the modification done on the merged detached object ?" Watch "Will hibernate take care of the modification done on the merged detached object ?" New topic
Author

Will hibernate take care of the modification done on the merged detached object ?

sunil vp
Greenhorn

Joined: Sep 27, 2013
Posts: 3
In a container managed transaction i get a detached object and merge it so that the detached object is brought to managed state.My initial question is by caching the Pojo java objects and merging is a better idea to get the object into session or performing the get of the data from the DB to get in to session context a better idea in terms of cost of operation/time involved in getting the data from the DB?If i am performing an merge at start to get the object into the session context and doing the modification on this merged object will the hibernate take care of generating all the required sql statements and at the end will it be taken care ?

Please comment back which is better approach to get the entity to session , using a merge of the cached detached object or fetching the data from the DB is lesser time consumption?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Are you using your own caching mechanism for your POJOs? I wouldn't recommend that given that Hibernate has its own:

Hibernate 3:
http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/performance.html

Hibernate 4:
http://docs.jboss.org/hibernate/orm/4.0/manual/en-US/html/performance.html
sunil vp
Greenhorn

Joined: Sep 27, 2013
Posts: 3
@james Boswell thanks for the replay . i have one question which is not answered if i bring back the detached object to memory after the start of the session using merge and then later i perform some modifications on that entity will the container take care of the modification in the container managed transactions ?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Yes, within the same session, Hibernate will take care of this for you. You must persist the entity before you end the session.
sunil vp
Greenhorn

Joined: Sep 27, 2013
Posts: 3
So why should i persist at an end in an container managed transaction in EJB's? will hibernate not generate the update statements for me at the end of the transaction ?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

No, Hibernate will not do that for you automatically. You need to call persist so that at some point (shortly after the session ends), Hibernate will commit the changes. I believe if you call flush, you force Hibernate to perform the commit there and then.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Will hibernate take care of the modification done on the merged detached object ?