沉睡森林@漂在北京

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

            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);
          }
          }
            回復  更多評論
            

          主站蜘蛛池模板: 梁山县| 忻城县| 乌恰县| 海安县| 穆棱市| 甘泉县| 潜江市| 嘉黎县| 长汀县| 天全县| 旬邑县| 淮滨县| 英山县| 道孚县| 武清区| 黔西| 抚宁县| 图木舒克市| 太原市| 三江| 垫江县| 北海市| 芜湖县| 伊宁县| 柳州市| 平遥县| 青海省| 东明县| 万全县| 自治县| 望江县| 饶阳县| 兴业县| 深水埗区| 长沙县| 从化市| 泽普县| 孟津县| 千阳县| 襄汾县| 泗阳县|