A different object with the same Identifier value was already associated with the session.

Source: Internet
Author: User
[DH-OFFICE] 23:50:30 error [http-8080-5] newsaction. save (128) | a different object with the same Identifier value was already associated with the session: [com.sencloud.dh.oa.model.info. news #10060]; Nested exception is Org. hibernate. nonuniqueobjectexception: a different object with the same Identifier value was already associated with the session: [com.sencloud.dh.oa.model.info. news #10060]

This problem occurs today: you can solve it in the following ways.

1. A different object with the same Identifier value was already associated with the session.
cause of error: two identical identifiers but different entities exist in the same session in hibernate.
solution 1: Session. clean ()
PS: If saveorupdate (object) and other operations to change the data status are performed after the clean operation, "Found two representations of same Collection" may be reported.
solution 2: Session. refresh (object)
PS: when the object is not an existing data object in the database, the session cannot be used. refresh (object) because this method is used to retrieve the object from the hibernate session, if this object does not exist in the session, an error is returned. Therefore, when you use saveorupdate (object) you need to judge before.
solution 3: Session. Merge (object)
PS: the built-in method in hibernate, which is recommended.
2. Found two representations of same collection
cause of error: See figure 1.
solution: Session. Merge (object)
the preceding two exceptions often occur in one-to-multiple ing and multiple-to-multiple ing.

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.