Propagation behavior of Spring transactions

To make it easier to remember, I’ve divided it into three categories: current transactions supported, current transactions not supported, and other transactions.

Support current transactions

1, PROPAGATION_REQUIRED: Join the current transaction if it exists. If no current transaction exists, create a new one.

2, PROPAGATION_SUPPORTS: If a current transaction exists, join it. If there is no current transaction, it continues in a non-transactional manner.

3. PROPAGATION_MANDATORY: If a current transaction exists, add it. If there is no current transaction, an exception is thrown.

Current transactions are not supported

PROPAGATION_REQUIRES_NEW: Creates a transaction, and suspends it if it currently exists.

5, PROPAGATION_NOT_SUPPORTED: Runs in a non-transactional manner, and suspends a transaction if one currently exists.

6, PROPAGATION_NEVER: Runs non-transactionally, and throws an exception if a transaction currently exists

Other transactions

7, PROPAGATION_NESTED: If a transaction is currently running, it should run in a nested transaction, which can be committed or rolled back independently of the encapsulated transaction.

If an encapsulated transaction exists and the outer transaction throws an exception to roll back, then the inner transaction must be rolled back, whereas the inner transaction does not affect the outer transaction. If the encapsulated transaction does not exist, it is the same as PROPAGATION_REQUIRED.