关于Spring事务传播的问题 [英] Question about Spring transaction propagation

查看:35
本文介绍了关于Spring事务传播的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 Spring 事务传播的问题.

I have a question about Spring transaction propagation.

假设我使用 @Transactional(propagation = Propagation.REQUIRED) 来注释方法 m1().当执行逻辑进入m1()时,如果已经有交易,m1()会使用那个.在 m1() 之后,事务呢?它会结束还是仍然开放?(如果我在另一个方法中调用 m1(),并且在调用之后还有其他事情要做).

Suppose I use @Transactional(propagation = Propagation.REQUIRED) to annotate a method m1(). When execution logic enters m1(), if there is already a transaction, m1() will use that one. When after m1(), what about the transaction? It will end or still remain open? (if I call m1() in another method, and after the invocation there is still other things to do).

总而言之,我想知道当退出一个带注释的方法时,事务结束还是仍然保持打开状态?

In summary, I want to know when exiting an annotated method, the transaction ends or still remains open?

非常感谢.

推荐答案

Propagation.REQUIRED (documented here) 将创建一个新事务(如果当前线程不存在),或者将加入现有交易(如果存在).

Propagation.REQUIRED (documented here) will create a new transaction (if none exists for the current thread), or will join an existing transaction (if one exists).

当方法退出时,事务将完成(如果进入方法导致创建了一个事务),或者将保持事务打开(如果在输入方法时一个事务已经存在).换句话说,它是对称的,并且会将线程的事务状态保留在进入方法之前的相同状态.

When the method exits, then the transaction will be completed (if entering the method caused a transaction to be created), or will leave the transaction open (if a transaction already existed when the method was entered). In other, words, it's symmetrical, and will leave the thread's transactional state in the same state it was before the method was entered.

这篇关于关于Spring事务传播的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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