我在一个方法上,用了spring 的事务,方法中有几个访问数据库的操作。
其中一个操作,会抛出异常,这是正常逻辑范围内的,我捕获了异常,继续处理。
但spring却会因为这个异常,把事务终止掉,请问有什么办法让spring忽略这个异常,正常进行事务?我的异常中这样产生的:
数据库操作用了nowait方式的加锁select id from table where id = 'xxx' for update nowait;我的逻辑是,加锁取id为xxx的记录,如果被别的线程锁住了,会抛出异常,我捕获异常,继续取下一条id为'yyy'的记录,如果取到,则更新某些字段。这个select for update nowait的异常,是正常逻辑,我不希望中止事务。
应该咋处理啊?
其中一个操作,会抛出异常,这是正常逻辑范围内的,我捕获了异常,继续处理。
但spring却会因为这个异常,把事务终止掉,请问有什么办法让spring忽略这个异常,正常进行事务?我的异常中这样产生的:
数据库操作用了nowait方式的加锁select id from table where id = 'xxx' for update nowait;我的逻辑是,加锁取id为xxx的记录,如果被别的线程锁住了,会抛出异常,我捕获异常,继续取下一条id为'yyy'的记录,如果取到,则更新某些字段。这个select for update nowait的异常,是正常逻辑,我不希望中止事务。
应该咋处理啊?
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 用于配置详细的事务语义 -->
<tx:attributes>
<!-- 所有以'update'开头的方法是read-only的 -->
<tx:method name="update*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<!-- 所有以'get'开头的方法是read-only的 -->
<tx:method name="get*" read-only="true" />
<!-- 其他方法使用默认的事务设置 -->
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice> <tx:annotation-driven transaction-manager="transactionManager"/>
<aop:config>
<aop:pointcut id="profScheStrategiesManager_update"
expression="execution(* com.woods..ProfScheStrategiesManager.update*(..))" />
<aop:advisor pointcut-ref="profScheStrategiesManager_update" advice-ref="txAdvice" />
</aop:config>
注解是这样配置的
@Transactional(value="transactionManager", propagation=Propagation.REQUIRED, isolation=Isolation.READ_COMMITTED,
timeout=-1, noRollbackFor=org.springframework.dao.CannotAcquireLockException.class)
public Map<String, Object> updateGetForSchedule(Map<String, Object> vParam) {
......
}