Welcome to the new Spring.io forums!
If this is your first visit, be sure to check out the
by clicking the link above, and for security reasons, use the
forgot password link to reset your password..
You may have to register before you can post: click the register
link above to proceed. To start viewing messages, select the forum that you want to visit
from the selection below.
No announcement yet.
getHibernateTemplate().merge vs. saveOrUpdate()Page Title Module
// Note: Hibernate3's merge operation does not reassociate the object with the
// current Hibernate Session. Instead, it will always copy the state over to
// a registered representation of the entity. In case of a new entity, it will
// register a copy as well, but will not update the id of the passed-in object.
// To still update the ids of the original objects too, we need to register
// Spring's IdTransferringMergeEventListener on our SessionFactory.
IMHO, saveOrUpdate is still needed as it's semantics are different then with merge.
We had quite a lot a lot of NonUniqueObjectExceptions when for example we get an updated object from the object and we try to save it while a previous findAll has already associated the object with the session(especially with OSIV filter).
As the methods are written independently the object association is unknown and the solution was using an unmananged session for saving or getting the list. With merge things are a lot easier.
I haven't checked but I think merge is more 'expensive' then saveOrUpdate so using it through out the application is going to add a penalty.