在執(zhí)行service中一個(gè)方法bumenAuth()時(shí)出現(xiàn)錯(cuò)誤:
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
查看srping中事務(wù)管理配置:
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="clear*">PROPAGATION_REQUIRED</prop>
<prop key="build*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
看了之后才知道,原來(lái)的事務(wù)策略的<prop key="*">PROPAGATION_REQUIRED</prop>被刪除后,bumenAuth()方法后忘了修改,所以導(dǎo)致報(bào)上述的錯(cuò)誤
修改方法一:
將此方法修改為update或者build,add....等上述策略名稱開頭的方法:如:updateBumenAuth()
修改方法二:
增加<prop key="*">PROPAGATION_REQUIRED</prop>即可
修改方法三:
將web.xml下的
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
中的singleSession值修改為false,即不限制整個(gè)過程用同一個(gè)session,但缺點(diǎn)是Hibernate Session的Instance可能會(huì)大增,使用的JDBC Connection量也會(huì)大增,如果Connection Pool的maxPoolSize設(shè)得太小,很容易就出問題
|