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));
这样就解决问题了。
相关文章推荐
- 解决HibernateException: Illegal attempt to associate a collection with two open sessions
- 解决HibernateException: Illegal attempt to associate a collection with two open sessions
- 解决HibernateException: Illegal attempt to associate a collection with two open sessions
- 异常描述:hibernate懒加载中,用OpenSessionInViewFilter解决之后,同时对一个collection创建两个session访问导致异常(Illegal attempt to associate a collection with two open sessions)
- 【Hibernate】Illegal attempt to associate a collection with two open sessions
- Illegal attempt to associate a collection with two open sessions
- Hibernate 异常: Illegal attempt to associate a collection with two open sessions
- SSH架构中Illegal attempt to associate a collection with two open sessions 问题
- HibernateException: Illegal attempt to associate a collection with two open sessions
- 新启动线程时保存对象时报 错HibernateException: Illegal attempt to associate a collection with two open sessions
- OpenSessionInViewFilter的两个异常:Illegal attempt to associate a collection with two open sessions
- Hibernate 异常: Illegal attempt to associate a collection with two open sessions
- Illegal attempt to associate a collection with two open sessions;
- Illegal attempt to associate a collection with two open sessions
- 错误:Illegal attempt to associate a collection with two open sessions
- org.hibernate.HibernateException:Illegal attempt to associate a collection with two open sessions; 问题。
- Hibernate 异常:Illegal attempt to associate a collection with two open sessions
- Hibernate Merge (Illegal attempt to associate a collection with two open sessions)
- Illegal attempt to associate a collection with two open sessions.
- Illegal attempt to associate a collection with two open sessions