<!-- lang: java --> org.springframework.orm.hibernate3.HibernateSystemException: Illegal attempt to associate a collection with two open sessions;
错误缘由分析: 由于Hibernate默认是只容许单个session存在,若是有两个session同时open,并同一个collection进行操做,Hibernate是没法判断使用那个。 在wel.xml文件中配置了opensession Filter,设置为singleSession。java
<!-- lang: xml --> <filter> <filter-name>hibernateFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> </filter>
可是若是咱们想经过改变singleSession为false解决问题,我我的认为这个是不合理作法,仍是该想其余解决方法。我提供一个解决方法供你们参考。spring
解决方法: 并且我经过google的搜索的时候,发现这个问题常常出如今1:N的状况下。因此在这种状况下要更为注意open two session这个问题,以避免浪费必要的时间在解决错误上。数据库
一、将两个同时对数据库操做的(update/save)法写在一个事务中。session
二、将Hibernate的update方法改成merge。google