本文介绍了嵌套@Transactional的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在spring中嵌套@Transactional注释的方法?考虑这样的事情:
中的第二个 @Transactional / code>不是必需的,因为默认情况下 @Transactional 传播了 REQUIRED $ c $因此,由方法 a()调用的方法将是事务性的。如果您想在方法 a()所调用的方法内开始新的事务,则需要修改传播规则。阅读有关交易传播。Is it possible to nest @Transactional annotated methods in spring? Consider something like this:
@Transactional public void a() { obj.b(); } @Transactional public void b() { // ... }What happens in such a case if I rollback in b() and rollback in a() ?
解决方案The second @Transactional annotation on method b() is not required because by default @Transactional has a propagation of REQUIRED, therefore methods called by method a() will be transactional. If you are looking to start a new transaction within a method called by method a() you will need to modify the propagation rules. Read about Transaction Propagation.
这篇关于嵌套@Transactional的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!