沉睡森林@漂在北京

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

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

          主站蜘蛛池模板: 襄城县| 腾冲县| 延长县| 巩义市| 松阳县| 巩留县| 宝山区| 雷州市| 且末县| 嘉义县| 盘锦市| 灵川县| 郸城县| 石台县| 普陀区| 永定县| 金山区| 西吉县| 普格县| 洛宁县| 祁东县| 阜宁县| 南开区| 玉门市| 黄龙县| 龙泉市| 伊宁县| 蒙城县| 梓潼县| 方山县| 黎川县| 丽江市| 满城县| 樟树市| 册亨县| 泸水县| 久治县| 石林| 五寨县| 兰西县| 淄博市|