Hello Guys! today we will deal with “org.hibernate.NonUniqueObjectException “.
Basically, what hibernate is saying is that you have two objects which have the same identifier (same primary key) .
There are 2 cases where this exception occur.
1.When hibernate is trying to persist an object and object that is already persistent [object already saved in database].
2. When an entity is persisted and detached from the session. Another instance of this entity is requested to hibernate. This second instance stayed attached to the session. The first instance is modified.
When hibernate persist the second instance, it is not able to choose what is the correct content to persist and throw an “NonUniqueObjectException.”
Solution. use hibernate merge method instead use save.