您的位置:首页 > 运维架构

HibernateException: Illegal attempt to associate a collection with two open sessions(解决方法)

2012-08-27 12:40 423 查看
在项目中遇到这个 HibernateException: Illegal attempt to associate a collection with two open sessions. 一查代码发现是因为在service中存在两个不同的hibernate session都同时引用了同一个collection对象,一个是load(),一个是saveOrUpdate(),简单的修改方法: hibernate session 的 merge() 方法。hibernate3.0以上可以使用merge()来合并两个session中的同一对。

将原来的代码:

this.classificationDAO.saveOrUpdate(classification);


改成

this.classificationDAO.saveOrUpdate(this.classificationDAO.merge(classification));


这样就解决问题了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐