Possible Duplicate:
Spring + Hibernate : a different object with the same identifier value was already associated with the session
I've loaded an object X from DB using hibernateTemplate find by id, then I get some attributes from that object and added it to another object Y from the same type which was also loaded by the same X id. Then when I tried to saveOrUpdate
object Y, hibernate throws exception a different object with the same identifier value was already associated with the session, which I think means that object X is associated with that attribute in the same session, so Y can't be saved or updated and affect also that attribute.
How can I remove object X from session so it's no longer associated with that attribute
I tried to use merge instead of saveOrUpdate
and it's working fine, but is it the same as saveOrUpdate
? I mean can I depend on it to add new records or update them?