<!-- 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