What are the different propagation mechanisms in Spring transactions?
In Spring, there are several types of transaction propagation methods available.
- Option:
REQUIRED (default): If a transaction currently exists, join that transaction; if no transaction currently exists, create a new transaction. - If there is currently a transaction, it will be added to that transaction; if there is no current transaction, it will be executed in a non-transactional manner.
- MANDATORY: Join the current transaction if it exists; throw an exception if it does not.
- REQUIRES_NEW: A new transaction is created regardless of whether a transaction currently exists. If there is an existing transaction, it will be suspended.
- NOT_SUPPORTED: Perform the operation in a non-transactional manner. If there is currently a transaction, it will be suspended.
- NEVER: Perform actions in a non-transactional manner. Throw an exception if there is currently a transaction in progress.
- If there is an active transaction, the nested transaction will be executed within it. If there is no active transaction, a new one will be created. Nested transactions can be committed or rolled back independently without affecting the outer transaction’s commit or rollback.