在web.xml文件中配置OpenSessionInViewFilter
????<filter>
????????<filter-name>hibernateFilter</filter-name>
????????<filter-class>
????????????org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
????????</filter-class>
??? </filter>
在spring的事務(wù)配置中:
<aop:config>
????<aop:advisor?id="managerTx"?advice-ref="txAdvice"
????????pointcut="execution(*?*..service.*Manager.*(..))"?order="2"?/>
</aop:config>
<tx:advice?id="txAdvice">
????<tx:attributes>
????????<tx:method?name="get*"?read-only="true"?/>
????????<tx:method?name="find*"?read-only="true"?/>
????????<tx:method?name="*"?/>
????</tx:attributes>
</tx:advice>
這樣的配置,當(dāng)在容器中通過(guò)action調(diào)用service代碼保存對(duì)象時(shí),不能成功保存對(duì)象,
同時(shí)出現(xiàn)如下類似錯(cuò)誤:
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.
這時(shí)修改filter的配置,增加如下代碼:
????<filter>
????????<filter-name>hibernateFilter</filter-name>
????????<filter-class>
????????????org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
????????</filter-class>
????????<init-param>
????????????<param-name>singleSession</param-name>
????????????<param-value>false</param-value>
????????</init-param>
????</filter>
這樣就能成功保存對(duì)象了。
===================================================================
額。。。上面那個(gè)配置等于不用OpenSessionInViewFilter。。。 沒(méi)意義。。
posted on 2007-04-11 20:33
想飛的魚(yú) 閱讀(4764)
評(píng)論(3) 編輯 收藏 所屬分類:
framework