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…