【Hibernate】Illegal attempt to associate a collection with two open sessions
2014-09-17 18:29
274 查看
今天在用Hibernate对对象进行修改操作的时候报了这个错。
之前一直没什么错误,但是今天修改了一下表结构,增加了一个OneToMany的映射。
所以在我获取对象,重新set一个变量之后就报了这个错误了。
网上查了一下,说是不同session直接对象的操作造成的,原因还有待查明。
目前暂时采用了下面的方法
在修改完对象值之后,给对象的OneToMany的List设置null值就可以了。
先做下备注。
之前一直没什么错误,但是今天修改了一下表结构,增加了一个OneToMany的映射。
所以在我获取对象,重新set一个变量之后就报了这个错误了。
Illegal attempt to associate a collection with two open sessions; nested exception is org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
网上查了一下,说是不同session直接对象的操作造成的,原因还有待查明。
目前暂时采用了下面的方法
在修改完对象值之后,给对象的OneToMany的List设置null值就可以了。
Dao<Resources> resourcesDao=TitanContext.getDaoProxy(Resources.class); Resources resource = resourcesDao.find(id); resource.setClickCount(resource.getClickCount()+1); resource.setResourcePeriod(null); resourcesDao.update(resource);
先做下备注。
相关文章推荐
- HibernateException: Illegal attempt to associate a collection with two open sessions
- Hibernate Merge (Illegal attempt to associate a collection with two open sessions)
- 异常描述:hibernate懒加载中,用OpenSessionInViewFilter解决之后,同时对一个collection创建两个session访问导致异常(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 错误:Illegal attempt to associate a collection with two open sessions
- 新启动线程时保存对象时报 错HibernateException: 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
- 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.
- net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open session
- 解决HibernateException: 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
- 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
- SSH架构中Illegal attempt to associate a collection with two open sessions 问题