Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Difference Between saveOrUpdate, update and merge methods
PostPosted: Tue Aug 14, 2012 7:20 am 
Newbie

Joined: Tue Aug 14, 2012 7:11 am
Posts: 2
I have gone through the Hibernate documentation on these methods but unable to understand the logic behind these 3 methods. If someone can please explain this with the code example with detached objects and session objects, it will be really helpful. I tried to go through various forums also, but didn't get much information over there.

saveOrUpdate: It either inserts a new record if one doesn't exist in db or updates the existing one if one with the given id exist in the db. But, how will it behave in case of detached objects?

update : It will reattach the object to the session. Suppose, I get an object say object1 using session1 and then session1 is closed, Now, the object1 is detached. And, I opened a new sessoin session2 and call update with object1 on this session session2, what will happen? What will happen if I call saveOrUpdate in this case rather than update method?

merge: what will happen if I call merge method rather than above two methods in above scenario.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.