This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 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 ?
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.