异常描述:hibernate懒加载中,用OpenSessionInViewFilter解决之后,同时对一个collection创建两个session访问导致异常(Illegal attempt to associate a collection with two open sessions)
2017-05-06 21:07
851 查看
在保存的时候如果使用以下方法就会报错
解决:使用merge()方法就可以解决异常。。。
merge()方法的解释:
传入的参数在数据库中不存在的时候会添加一条数据,根据主键判断已存在的时候会更新这条数据,merge在执行更新之前会将两个标识符相同的对象进行合并,具体合并的方向是向数据库中存在的记录合并。
注意:merge方法在执行之前都回去缓存中找是不是有相应的记录,也就是会有一条select语句,执行改语句的目的是为了判断该对象是否被修改了。而update就不管这些,直接就一条update语句。
具体和session有什么关系待以后再研究。
解决:使用merge()方法就可以解决异常。。。
merge()方法的解释:
传入的参数在数据库中不存在的时候会添加一条数据,根据主键判断已存在的时候会更新这条数据,merge在执行更新之前会将两个标识符相同的对象进行合并,具体合并的方向是向数据库中存在的记录合并。
注意:merge方法在执行之前都回去缓存中找是不是有相应的记录,也就是会有一条select语句,执行改语句的目的是为了判断该对象是否被修改了。而update就不管这些,直接就一条update语句。
具体和session有什么关系待以后再研究。
相关文章推荐
- 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 异常: 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
- org.hibernate.HibernateException: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
- 新启动线程时保存对象时报 错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)
- HibernateException: 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
- Illegal attempt to associate a collection with two open sessions
- Illegal attempt to associate a collection with two open session问题
- 【Spring】OpenSessionInViewFilter解决Hibernate懒加载异常
- Illegal attempt to associate a collection with two open sessions
- SSH架构中Illegal attempt to associate a collection with two open sessions 问题