Simultaneous operation of two databases: error illegal attempt to associate a collection with two open sessions

Source: Internet
Author: User
Tags sessions

Today I inserted 1 data in an SSH that operates two databases

Error illegal attempt to associate a collection with both open sessions

Here are the answers: http://fuaotech.iteye.com/blog/1298826

Use the Hibenate merge method instead of Save, update, and so on.
The merge and Saveorupdate methods differ in that the merge method is the object that transforms the object we provide into a managed state, whereas saveorupdate turns the object we provide into a persisted object. , said the popular point is: Saveorupdate after the object will be included in the session management, the state of the object will be synchronized with the database, query the object will be directly from the session, the merge object will not be included in the session management, The object will be queried again or taken from the database. So the general recommendation is to use the merge

This.gethibernatetemplate (). Save (data) in the Missiondaoimpl class. The Save method is changed to the merge method

Use this method: public boolean addData (Object data) throws Exception {
This.gethibernatetemplate (). Save (data);
return true;
}

Operation of two databases simultaneously: error illegal attempt to associate a collection with two open sessions

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.