沉睡森林@漂在北京

          本處文章除注明“轉載”外均為原創,轉載請注明出處。

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            152 隨筆 :: 4 文章 :: 114 評論 :: 0 Trackbacks

          問題描述:

          Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition. 

          posted on 2009-05-21 20:28 王總兵 閱讀(215) 評論(1)  編輯  收藏 所屬分類: Spring

          評論

          # re: Spring和Hibernate結合時遇到的問題 2009-05-21 20:30 王兵
          下面是轉自【http://www.aygfsteel.com/i369/articles/240039.html
          一般這個錯誤是事務引起的,如果確定事務沒有問題,還是有這個錯,可以重寫OpenSessionInViewFilter的2個方法
          在myfaces的wiki里提供了OpenSessionInViewFilter的一個子類如下:
          public class OpenSessionInViewFilter extends org.springframework.orm.hibernate3.support.OpenSessionInViewFilter {

          /**
          * we do a different flushmode than in the codebase
          * here
          */
          protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
          Session session = SessionFactoryUtils.getSession(sessionFactory, true);
          session.setFlushMode(FlushMode.COMMIT);
          return session;
          }
          /**
          * we do an explicit flush here just in case
          * we do not have an automated flush
          */
          protected void closeSession(Session session, SessionFactory factory) {
          session.flush();
          super.closeSession(session, factory);
          }
          }
            回復  更多評論
            

          主站蜘蛛池模板: 扶风县| 吉木乃县| 绥芬河市| 娄底市| 湖口县| 思茅市| 法库县| 正蓝旗| 城步| 称多县| 南开区| 长子县| 舟山市| 定边县| 临汾市| 清河县| 三都| 淳化县| 平江县| 星子县| 大石桥市| 永登县| 德安县| 五家渠市| 屯昌县| 黄山市| 宜都市| 岢岚县| 宁远县| 阿坝| 泗阳县| 富宁县| 吉木萨尔县| 佳木斯市| 牟定县| 佛教| 黄浦区| 普格县| 碌曲县| 鸡泽县| 红桥区|