Hibernate: Merge vs SaveOrUpdate By seung | September 18, 2008 In my previous and current project, I have run into cases where I needed to save an object to database using hibernate, and from time to time, I run into some sort of Hibernate Session Exception. I did a bit of google search, and it turns out that when saving an object, I needed to make sure the object was attached to Hibernate session. This can be very tedious issue, since that means if you need to save an object that is not attached to a session, you need to do these. Retrieve the object using the Id value found within the object passed to you. Update the property values one by one Save the object back within the same Hibernate Session Here’s a quick summary that I found out about MERGE and SaveOrUpdate. void saveOrUpdate(object)->object must be attached to a hibernate session (including all sub objects within the object), and once save/update is done, the object reflects the ...
The reason for doing the work is to create something useful that helps people. Please click the ads if my articles are useful for you. Definitely, that's not enough. My target is working at some great organizations, such that one day, all the people with internet access can benefit from the service I contributed.