同时操作两个数据库:报错Illegal attempt to associate a collection with two open sessions

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了同时操作两个数据库:报错Illegal attempt to associate a collection with two open sessions相关的知识,希望对你有一定的参考价值。

今天我在一个操作两个数据库的SSH里 同时插入1条数据  

报错 Illegal attempt to associate a collection with two open sessions

在这里有答案:http://fuaotech.iteye.com/blog/1298826

使用hibenate的merge方法代替save、update等方法。 
merge和saveOrUpdate方法区别在于:merge方法是把我们提供的对象转变为托管状态的对象;而saveOrUpdate则是把我们提供的对象变成一个持久化对象;说的通俗一点就是:saveOrUpdate后的对象会纳入session的管理,对象的状态会跟数据库同步,再次查询该对象会直接从session中取,merge后的对 象不会纳入session的管理,再次查询该对象还是会从数据库中取。所以一般建议用merge 

将MissionDaoImpl类中的 this.getHibernateTemplate().save(data);    save方法改为了merge方法 

将此方法:public boolean addData(Object data) throws Exception { 
this.getHibernateTemplate().save(data); 
return true; 

以上是关于同时操作两个数据库:报错Illegal attempt to associate a collection with two open sessions的主要内容,如果未能解决你的问题,请参考以下文章

操作错误: lsnrctl启动报错(lsnrctl start),Linux Error: 29: Illegal seek

Ajax方式上传文件报错"Uncaught TypeError: Illegal invocation"

jQuery跳出each循环:JS报错:illegal break statement

Uncaught TypeError: Illegal invocation报错简单直接解决方案

mysql union语句报错:Error Code: 1271. Illegal mix of collations for operation ‘UNION‘

ajax--表单带file数据提交报错Uncaught TypeError: Illegal invocation