spring 控制事物readOnly的异常错误解释

本文介绍Spring框架中如何通过XML配置文件进行事务管理,包括配置事务管理器、定义事务通知及方法级事务传播行为等。同时,针对事务配置中常见的只读属性导致的数据修改操作异常进行了分析,并提供了解决思路。

xml配置 

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
		<property name="sessionFactory" ref="sessionFactory" />
</bean>


<!-- 事务通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
	<tx:attributes>
		<tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT"/>
		<tx:method name="add*" propagation="REQUIRED" isolation="DEFAULT"/>
		<tx:method name="edit*" propagation="REQUIRED" isolation="DEFAULT"/>
		<tx:method name="remove*" propagation="REQUIRED" isolation="DEFAULT"/>
		<tx:method name="*Tran"  propagation="REQUIRED" isolation="DEFAULT" />
		<tx:method name="*" propagation="REQUIRED" isolation="DEFAULT"/>
	</tx:attributes>
</tx:advice>

 

exception 提示

1.

Cause: java.sql.SQLException: Connection is read-only. 
Queries leading to data modification are not allowed

2.

cannot execute CREATE DATABASE in a read-only transaction

以上均是由springxml中check*  <prop key="*">readOnly</prop> 配置引起的,

方法的事务设置只读,说明调用这个方法时事务只能查询,不能增删改,这样就提高了性能,如果增删改,就会报错;

具体关于事物readOnly控制,可查看文章: http://boy00fly.iteye.com/blog/1142754 

 

转载于:https://my.oschina.net/java1314/blog/794054

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值