Nested @Transactional

对着背影说爱祢 提交于 2020-01-21 02:39:06

问题


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() ?


回答1:


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.



来源:https://stackoverflow.com/questions/6633870/nested-transactional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!