In my project, some time I have to load a object to edit them. Before this, I think, hibernate session is closed.
Some time before save the edited object (with saveOrUpdate
), I have to search (open session again) for a object in the database, and, maybe, the object returned by this search is the object I'll update. (I need this object for some validations and other things...)
After this, when I try to save the object, hibernate says that I have another object with the same identifier in the session.
I have implemented my own equals
and hashcode
methods, and I tried to do somethings, like session.evict(object)
, but, nothing works.
So, I use session.merge(object)
instead of session.saveOrUpdate(object)
, and it works.
But, I dont know exactly what is the consequences of doing this. I can simple replace saveOrUpdate
by merge
, or I will get some issues with it? Another thing I have to know about this?
Thanks in advance.