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.
|