Hibernatesystemexception:a different object with the same identifier value is already associated with the session.
This error is due to the existence of a cached object A in the session-level cache of Hibernate, and the same identifier for objects B and a that are not in the first-level cache, but they are not the same object, that is, the reference is not the same, so this exception is thrown.
The following code also throws an exception:
Image i = new image ();
I.setid (1);
Image j = session.load (image.class,1);
Session.delete (i);
Because I and J are both image objects and have the same identifier 1, the objects in session J and the object in the session that are not in session I are two objects, and their references are different. Therefore, an exception is thrown.
Solution: You can use Session.clear () to clear the session cache, and then hibernate session related operations.