隨筆 - 6  文章 - 129  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(14)

          隨筆檔案(6)

          文章分類(467)

          文章檔案(423)

          相冊

          收藏夾(18)

          JAVA

          搜索

          •  

          積分與排名

          • 積分 - 827240
          • 排名 - 49

          最新評論

          閱讀排行榜

          評論排行榜

          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.

          今天在做事務測試的時候,控制臺輸出了以上的錯誤信息,在網上找了一下,原來是我在web.xml
          文件中設置了OpenSessionInView .  將設置去掉就可以了.
          <!-- OpenSessionInView -->
            <filter>
             <filter-name>OpenSessionInViewFilter</filter-name>
             <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
            </filter>
            <filter-mapping>
             <filter-name>OpenSessionInViewFilter</filter-name>
             <url-pattern>*.action</url-pattern>
            </filter-mapping>
          或者加上事務設置

          <?xml version="1.0" encoding="UTF-8"?>
          <beans
           xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
              xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx
              http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
              http://www.springframework.org/schema/aop
              http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
           >
           <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"></property>
           </bean>
           
           <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
             <tx:method name="create*" propagation="REQUIRED"/>
             <tx:method name="update*" propagation="REQUIRED"/>
             <tx:method name="delete*" propagation="REQUIRED"/>
             <tx:method name="find*" propagation="REQUIRED" read-only="true"/>
             <tx:method name="*" read-only="true"/>
            </tx:attributes>
           </tx:advice>
           
           <aop:config>
            <aop:pointcut id="daoOperation" expression="execution(* dgut.ke.dao.*.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="daoOperation"/>
           </aop:config>
           
          </beans>

          網上又說
          盡管Open Session In View看起來還不錯,其實副作用不少??椿厣厦鍻penSessionInViewFilter的doFilterInternal方法代碼,這個方法實際上是被父類的doFilter調用的,因此,我們可以大約了解的OpenSessionInViewFilter調用流程: request(請求)->open session并開始transaction->controller->View(Jsp)->結束transaction并close session.

               一切看起來很正確,尤其是在本地開發測試的時候沒出現問題,但試想下如果流程中的某一步被阻塞的話,那在這期間connection就一直被占用而不釋放。最有可能被阻塞的就是在寫Jsp這步,一方面可能是頁面內容大,response.write的時間長,另一方面可能是網速慢,服務器與用戶間傳輸時間久。當大量這樣的情況出現時,就有連接池連接不足,造成頁面假死現象。

          Open Session In View是個雙刃劍,放在公網上內容多流量大的網站請慎用。




          posted on 2007-11-16 16:51 Ke 閱讀(1952) 評論(0)  編輯  收藏 所屬分類: exception
          主站蜘蛛池模板: 东安县| 乌恰县| 确山县| 凤山县| 松原市| 长宁县| 新和县| 云霄县| 曲麻莱县| 南昌县| 巫溪县| 大化| 牙克石市| 盐山县| 中西区| 永清县| 鸡西市| 铁岭市| 巍山| 三台县| 平顶山市| 麻城市| 洪洞县| 廊坊市| 双鸭山市| 邮箱| 遵义市| 开化县| 拉萨市| 桑日县| 抚远县| 渭南市| 宁城县| 山阳县| 舒兰市| 永丰县| 申扎县| 青海省| 梅河口市| 霍城县| 班玛县|