Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sunil vp
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic