Differences between require_new and nested distribution in a Spring transaction

I cannot understand the difference in behavior between the distribution policies PROPAGATION_REQUIRES_NEW and PROPAGATION_NESTED . It seems to me that in both cases the current process is rolled back, but not the whole transaction. Any clue?

+45
java spring transactions
Sep 12
source share
3 answers

See this link: PROPAGATION_NESTED vs PROPAGATION_REQUIRES_NEW? Jรผrgen Holler explains this very well

PROPAGATION_REQUIRES_NEW launches a new independent "internal" transaction for this volume. This transaction will be completed or rollback is completely independent of the external transaction, having its own isolation volume, its own set of locks, etc. The external transaction will be suspended at the beginning of the internal and resumed after the internal is completed ....

PROPAGATION_NESTED, on the other hand, launches a "nested" transaction, which is a true subtransaction of an existing one. What will happen is that the save point will be taken at the beginning of the enclosed transaction. If the nested transaction failed, we will return to this savepoint. A nested transaction is part of an external transaction, so it will only be completed at the end of the external transaction ....

+65
Sep 12 2018-12-12T00:
source share

PROPAGATION_REQUIRES_NEW: uses a fully independent transaction for each affected area of โ€‹โ€‹the transaction. In this case, the main physical transactions are different and, therefore, can make or roll back independently from each other, while the external transaction does not depend on the state of rollback of the internal transaction.

PROPAGATION_NESTED: Uses a single physical transaction with multiple savepoints to which it can return. Such partial rollbacks allow the internal transaction area to initiate a rollback for its area, and the external transaction can continue the physical transaction, although some operations have been discarded. This parameter is usually mapped to JDBC savepoints, so it will only work with JDBC resource transactions.

check spring documentation

+10
Sep 12 '12 at 14:55
source share

Find the difference

 1.) Use of NESTED Transaction 

Perform inside a nested transaction, if the current transaction exists, behave like PROPAGATION_REQUIRED else. Nested transaction supported by Spring

2.) Using the REQUIRED Transaction Support the current transaction, create a new one if it does not exist. , This means for a banking domain, such as withdrawals, deposits, transaction updates

3.) Using transaction REQUIRES_NEW Create a new transaction and pause the current transaction, if it exists.

-3
Dec 04 '15 at 5:45
source share



All Articles