嵌套@Transactional [英] Nested @Transactional

查看:840
本文介绍了嵌套@Transactional的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在spring中嵌套@Transactional注释的方法?考虑这样的事情:

  @Transactional 
public void a(){
obj.b() ;
}

@Transactional
public void b(){
// ...
}

在这种情况下,如果我在b()中回滚并在()中回滚,会发生什么?

b()中的第二个 @Transactional / code>不是必需的,因为默认情况下 @Transactional 传播了 REQUIRED 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆