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.
i think this is a duplicate for What are the differences between Hibernate Session methods saveOrUpdate() and merge()? and a number of other questions, very common question indeed...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.