Hibernatesystemexception:a different object with the same identifier value is already associated with the session.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.