指定@Transactional rollbackFor还包括RuntimeException [英] Does Specifying @Transactional rollbackFor Also Include RuntimeException
本文介绍了指定@Transactional rollbackFor还包括RuntimeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@Transactional(rollbackFor = MyCheckedException.class)
public void foo() {
throw new RuntimeException();
}
这个事务是否会回滚,还是需要包含RuntimeException.class在注释中?
Will this transaction get rolled back, or do I need to include RuntimeException.class in the annotation as well?
推荐答案
不需要包含 RuntimeException
在 rollbackFor
列表中。它会处理,即使你没有提到它。
No need to include RuntimeException
in rollbackFor
list. It will handle that even if you do not mention it.
我已经尝试了jdbcTemplate: -
I've tried it out for jdbcTemplate:-
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = MyException.class)
public void updateSalary(final int increment){
jdbcTemplate.update("update EMPLOYEE set emp_salary = emp_salary + ?", increment);
throw new RuntimeException("update exception");
}
Output:
After Insertion:
1 Deepak 35000
2 Yogesh 35000
3 Aditya 35000
update exception
After Update
1 Deepak 35000
2 Yogesh 35000
3 Aditya 35000
这篇关于指定@Transactional rollbackFor还包括RuntimeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文