0
点赞
收藏
分享

微信扫一扫

not allowed in read-only mode (FlushMode.NEVER) 解决


spring 环境下做一个check*操作时,抛出异常

org.springframework.dao.InvalidDataAccessApiUsageException: 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.

 

后来发现,由于我在Action中调的方法名是checkXXXXX打头,而我的applicationContext.xml中的相关配置如下:


<bean id="transactionInterceptor"
		class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributes">
			<props>
				<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="view*">PROPAGATION_REQUIRED,readOnly</prop>				
				<prop key="merge*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="check*">PROPAGATION_REQUIRED,readOnly</prop>
				<prop key="insert*">
					PROPAGATION_REQUIRED,-GenericException
				</prop>


 即check打头的操作时,是不可操作数据库的,包括更新与增加数据。

找到原因后将


<prop key="check*">PROPAGATION_REQUIRED,readOnly</prop>


 改为


<prop key="check*">PROPAGATION_REQUIRED</prop>


 后,重启服务,问题解决。

 

 

 

 

 

 

 

举报

相关推荐

0 条评论