vickzhu

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            151 隨筆 :: 0 文章 :: 34 評論 :: 0 Trackbacks
          <2008年12月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          常用鏈接

          留言簿(6)

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          錯誤代碼:
          org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER) - turn your Session into FlushMode.AUTO or remove 'readOnly' marker from transaction definition
          錯誤原因:
          OpenSessionInViewFilter在getSession的時候,會把獲取回來的session的flush mode 設為FlushMode.NEVER。然后把該sessionFactory綁定到TransactionSynchronizationManager,使request的整個過程都使用同一個session,在請求過后再解除該sessionFactory的綁定,最后closeSessionIfNecessary根據該session是否已和transaction綁定來決定是否關閉session。在這個過程中,若HibernateTemplate 發現自當前session有不是readOnly的transaction,就會獲取到FlushMode.AUTO Session,使方法擁有寫權限。
          也即是,如果有不是readOnly的transaction就可以由Flush.NEVER轉為Flush.AUTO,擁有insert,update,delete操作權限,如果沒有transaction,并且沒有另外人為地設flush model的話,則doFilter的整個過程都是Flush.NEVER。所以受transaction保護的方法有寫權限,沒受保護的則沒有。
          參考文章:
          http://calvin.blog.javascud.org/post/46.htm
          解決辦法:
          采用spring的事務聲明,使方法受transaction控制
          <bean id="baseTransaction"
          class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
          abstract="true">
          <property name="transactionManager" ref="transactionManager"/>
          <property name="proxyTargetClass" value="true"/>
          <property name="transactionAttributes">
          <props>
          <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
          <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
          <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
          <prop key="save*">PROPAGATION_REQUIRED</prop>
          <prop key="add*">PROPAGATION_REQUIRED</prop>
          <prop key="update*">PROPAGATION_REQUIRED</prop>
          <prop key="remove*">PROPAGATION_REQUIRED</prop>
          </props>
          </property>
          </bean>
              <bean id="userService" parent="baseTransaction">
          <property name="target">
          <bean class="com.phopesoft.security.service.impl.UserServiceImpl"/>
          </property>
          </bean>

          posted on 2008-12-11 11:20 筱 筱 閱讀(450) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 宜宾市| 织金县| 凉城县| 财经| 东平县| 东宁县| 云安县| 宁安市| 江西省| 新津县| 大丰市| 大庆市| 新绛县| 克山县| 枣强县| 漳州市| 天长市| 环江| 雷波县| 拉萨市| 祥云县| 上杭县| 河西区| 江门市| 霍山县| 错那县| 乌兰察布市| 马鞍山市| 陆良县| 兴山县| 西盟| 南京市| 旺苍县| 怀安县| 衡东县| 汕头市| 都江堰市| 米林县| 玛曲县| 汤原县| 巴林左旗|