Today we have this problem:
Org.hibernate.nonuniqueobjectexception:a different object with the same identifier value is already associated with the Session: ...
The reason for this is because the same object, such as a person in the seession saved a copy, and the addition of the other object, such as company, because of the association, from the database get a person, The person is the same person as the person in the seession, and the get-out person is set to the company, like this, Compnay.setperson (person). This error occurred while adding company.
On the Internet, when adding object, do one of these operations, that is, to merge the same object:
Object = Session.merge (object);
and then save
Session.save (object);
I tried it, and I can fix it.
But because of my operation, after the addition of a modified operation, the increase is successful, but at the time of the modification of a new error, so my Final solution is:
Use the procedure to judge, in taking person's time, the session has to take from the session, no more get out, and finally save company, there is no problem.
It is also possible to determine in action whether the object is already present in the sessiion, if it exists, do not go to the database to take it, or take it out to determine if the object and the session is consistent, if consistent with the session can be
Reproduced in: http://blog.csdn.net/xinmashang/article/category/1120644
Org.hibernate.nonuniqueobjectexception:a different object with the same identifier value was alread---------program error