Resolve a different object with the same identifier value is already associated with the session error

Source: Internet
Author: User

20:41:15

Today do a saveorupdate operation error:

Org.springframework.orm.hibernate3.hibernatesystemexception:a different object with the same identifier value is Already associated with the session: [com.xshcar.carcloud.entity.uboxtbl#1291]; Nested exception is org.hibernate.nonuniqueobjectexception:a different object with the same identifier value was already Associated with the session: [com.xshcar.carcloud.entity.uboxtbl#1291]

A classic hibernate error: A different object with the same identifier value is already associated with the session XXXX
hibernate3.0 using merge () to merge the same object in the two session

Solve:

Call Hibernate's gethibernatetemplate (). Merge (Object) method on the Daoimpl layer;

 Public Boolean executeupdate (T-t)        {boolean b=true;         Try {       T= (t)this. Gethibernatetemplate (). Getsessionfactory (). Getcurrentsession (). Merge (t);            Gethibernatetemplate (). Update (t);         Catch (DataAccessException e) {            e.printstacktrace ();            b=false;        }                     return b;    }

 

Resolve a different object with the same identifier value is already associated with the session error

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.