解决HibernateException: Illegal attempt to associate a collection with two open sessions
来源:互联网 发布:php ext 编辑:程序博客网 时间:2024/05/16 09:40
在项目中遇到这个 HibernateException: Illegal attempt to associate a collection with two open sessions. 一查代码发现是因为在service中存在两个不同的hibernate session都同时引用了同一个collection对象,一个是load(),一个是saveOrUpdate().由于项目是以前的项目,所以代码很不规范,也很“庞大”(一个方法超过1000行),不想太伤筋动骨的修改。
于是找到了一个简单的修改方法: hibernate session 的 merge() 方法。hibernate3.0以上可以使用merge()来合并两个session中的同一对。
将原来的代码:
hbSession.saveOrUpdate(closureTask);改作:
hbSession.saveOrUpdate(hbSession.merge(closureTask));搞定!!
0 0
- 解决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
- 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.
- 新启动线程时保存对象时报 错HibernateException: Illegal attempt to associate a collection with two open sessions
- net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open session
- Hibernate 异常: Illegal attempt to associate a collection with two open sessions
- SSH架构中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
- OpenSessionInViewFilter的两个异常:Illegal attempt to associate a collection with two open sessions
- Hibernate 异常: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)
- SSH架构中Illegal attempt to associate a collection with two open sessions 问题
- java并发之原子性与可见性(一)
- 5道最基本的并查集- -!
- nodejs npm安装expressjs
- Let 与 Set 的不同用法
- Ubuntu 系统 Update-rc.d 命令
- 解决HibernateException: Illegal attempt to associate a collection with two open sessions
- php反射api
- 软件测试原则
- mysql数据库重命名语句
- VB 让别的程序在自己窗体中运行
- Python学习心得new
- java.lang.ClassNotFoundException:数据库驱动加载失败
- chapter 25 An Overview of the C API
- springMVC3学习(二)--ModelAndView对象