简体   繁体   English

关于Spring事务传播的问题

[英]Question about Spring transaction propagation

I have a question about Spring transaction propagation .我有一个关于 Spring事务传播的问题。

Suppose I use @Transactional(propagation = Propagation.REQUIRED) to annotate a method m1() .假设我使用@Transactional(propagation = Propagation.REQUIRED)注释方法m1() When execution logic enters m1() , if there is already a transaction, m1() will use that one.当执行逻辑进入m1() ,如果已经存在事务,则m1()将使用该事务。 When after m1() , what about the transaction?m1() ,交易呢? 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). (如果我在另一个方法中调用m1() ,并且在调用之后还有其他事情要做)。

In summary, I want to know when exiting an annotated method, the transaction ends or still remains open?总之,我想知道退出带注释的方法时,事务结束还是仍然保持打开状态?

Great thanks.万分感谢。

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). Propagation.REQUIRED在此处记录)将创建一个新事务(如果当前线程不存在),或者将加入现有事务(如果存在)。

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.换句话说,它是对称的,并且会使线程的事务状态与进入方法之前的状态相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM