简体   繁体   English

Spring 事务中 requires_new 和嵌套传播的区别

[英]Differences between requires_new and nested propagation in Spring transactions

I can't understand the behavior difference between the PROPAGATION_REQUIRES_NEW and PROPAGATION_NESTED propagation policies.我无法理解PROPAGATION_REQUIRES_NEWPROPAGATION_NESTED传播策略之间的行为差​​异。 It seems to me that in both cases, the current process is rollbacked but not the whole transaction.在我看来,在这两种情况下,当前进程都会回滚,但不会回滚整个事务。 Any clue?有什么线索吗?

See this link: PROPAGATION_NESTED versus PROPAGATION_REQUIRES_NEW?请参阅此链接: PROPAGATION_NESTED 与 PROPAGATION_REQUIRES_NEW? Juergen Hoeller explain it very well. Juergen Hoeller 解释得很好。 -- the Spring Source Forum is completely offline sice February 28, 2019, but you can read the relevant part of the article in the quote below -- Spring Source Forum于2019年2月28日完全离线,但您可以在下面的引用中阅读文章的相关部分

PROPAGATION_REQUIRES_NEW starts a new, independent "inner" transaction for the given scope. PROPAGATION_REQUIRES_NEW 为给定范围启动一个新的、独立的“内部”事务。 This transaction will be committed or rolled back completely independent from the outer transaction, having its own isolation scope, its own set of locks, etc. The outer transaction will get suspended at the beginning of the inner one, and resumed once the inner one has completed.该事务将完全独立于外部事务提交或回滚,具有自己的隔离范围、自己的一组锁等。外部事务将在内部事务开始时暂停,并在内部事务完成后恢复完全的。 ... ...

PROPAGATION_NESTED on the other hand starts a "nested" transaction, which is a true subtransaction of the existing one.另一方面,PROPAGATION_NESTED 启动一个“嵌套”事务,它是现有事务的真正子事务。 What will happen is that a savepoint will be taken at the start of the nested transaction.将会发生的情况是在嵌套事务开始时将采用一个保存点。 Íf the nested transaction fails, we will roll back to that savepoint. Í如果嵌套事务失败,我们将回滚到该保存点。 The nested transaction is part of of the outer transaction, so it will only be committed at the end of of the outer transaction.嵌套事务是外部事务的一部分,因此只会在外部事务结束时提交。 ... ...

PROPAGATION_REQUIRES_NEW : uses a completely independent transaction for each affected transaction scope. PROPAGATION_REQUIRES_NEW :对每个受影响的事务范围使用完全独立的事务。 In that case, the underlying physical transactions are different and hence can commit or roll back independently, with an outer transaction not affected by an inner transaction's rollback status.在这种情况下,底层物理事务是不同的,因此可以独立提交或回滚,外部事务不受内部事务回滚状态的影响。

PROPAGATION_NESTED : uses a single physical transaction with multiple savepoints that it can roll back to. PROPAGATION_NESTED :使用具有多个可以回滚的保存点的单个物理事务。 Such partial rollbacks allow an inner transaction scope to trigger a rollback for its scope, with the outer transaction being able to continue the physical transaction despite some operations having been rolled back.这种部分回滚允许内部事务作用域触发其作用域的回滚,而外部事务能够继续物理事务,尽管某些操作已经回滚。 This setting is typically mapped onto JDBC savepoints, so will only work with JDBC resource transactions.此设置通常映射到 JDBC 保存点,因此仅适用于 JDBC 资源事务。

check spring documentation检查弹簧文档

Please find the difference请找出不同之处

1.) Use of NESTED Transaction

Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else.如果当前事务存在,则在嵌套事务中执行,其他行为类似于 PROPAGATION_REQUIRED。 Nested transaction is supporting by Spring Spring 支持嵌套事务

2.)Use of REQUIRED Transaction Support a current transaction, create a new one if none exists. 2.) 使用 REQUIRED Transaction 支持当前事务,如果不存在则创建一个新事务。 . . It means for banking domain like withdraw,deposit, update the transaction这意味着银行域,如取款,存款,更新交易

3.) Use of REQUIRES_NEW Transaction Create a new transaction, and suspend the current transaction if one exists. 3.) REQUIRES_NEW 事务的使用 创建一个新事务,如果存在则挂起当前事务。

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

相关问题 Spring事务中REQUIRES_NEW和NESTED传播行为的差异 - Differences in behaviour of REQUIRES_NEW and NESTED propagation in Spring transactions 循环传播新事务(使用REQUIRES_NEW)不能按预期方式进行 - Propagation of new transactions (using REQUIRES_NEW) in a loop is not working as expected Spring 事务从 NOT_SUPPORTED 到 REQUIRES_NEW 的传播 - Spring Transaction Propagation from NOT_SUPPORTED to REQUIRES_NEW Spring 事务:从带有 requires 的方法调用的带有 requires_new 的方法 - Spring transactions: Method with requires_new called from a method with requires Spring数据gemfire不支持REQUIRES_NEW个事务 - REQUIRES_NEW transactions in not supported by Spring data gemfire Propagation Required 和 Requires_new 的示例 - Examples for Propagation Required and Requires_new 使用Tx传播丢失了有关Hibernate的更新REQUIRES_NEW - Lost updates on Hibernate using Tx propagation REQUIRES_NEW 为什么即使在Spring服务类的第二种方法中传播= Propagation.REQUIRES_NEW时,事务也会回滚? - Why are the transactions rolled back even when propagation=Propagation.REQUIRES_NEW in second method in Spring service class? EJB Transactions属性:NOT_SUPPORTED和REQUIRES_NEW - EJB Transactions attribute: NOT_SUPPORTED and REQUIRES_NEW Spring Propagation.REQUIRES_NEW - Spring Propagation.REQUIRES_NEW
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM