Transferred from: http://blog.csdn.net/zzzz3621/article/details/9776539
To see the meaning of the exception is already obvious, is that the primary key is not unique, in the last execution of the transaction SQL, the session cache contains multiple (>1) primary key objects.
Know that hibernate knows it has a first level cache, session level cache, in the execution of a transaction can manage persisted objects, at the end of the transaction execution of SQL, you can reduce the operation of the database.
To report this anomaly you have to take a closer look at your code, there must be a place to refer to the object has been different.
The following is a typical example:
[Java]View PlainCopy
- Public void Update (Object obj) {
- Fillobject (obj);
- Session.update (obj);
- }
- Public void Fillobject (Object obj) {
- Object obj2 = Session.load (Obj.getid ());
- Do set the properties of Obj2
- The wrong place
- obj = obj2;
- }
The right one should be
[HTML]View PlainCopy
- public void update (Object obj) {
- obj = fillobject (obj);
- Session.update (obj);
- }
- public object Fillobject (object obj) {
- Object obj2 = session.load (Obj.getid ());
- Do set the properties of Obj2
- return obj2;
- }
Error condition: When the Fillobject method is called, obj (Fillobject) is the state of 1, and the latter becomes 2. However, obj (update) always points to obj, and when the fillobject is executed, the session has stored the OBJ2 and then the obj is updated to the database with an error.
Org.hibernate.nonuniqueobjectexception:a different object with the same identifier value is Alread