[Spring Boot] Transactional Propagation Properties
In this article, different propagation properties will be tested.
Test code will make use of two services. To make it easier to distinguish the hierarchy of the two services, I will name them as
To make things simpler,
ParentService simply saves some data and invokes
ChildService like below:
For some transactional propagation properties (MANDATORY, SUPPORTS, NEVER, NOT_SUPPORTED, NESTED), some methods in
ParentService will not be annotated with
Transactional to see the effects of parent transaction.
ChildService will simply save some data and trigger a runtime exception to see if certain transaction propagation performs rollback or not. Each method will be annotated with a different propagation property to see how each behaves. A sample would look like below:
- REQUIRED (default) : Appends to currently active transaction or creates a new one if there is no active transaction.
- REQUIRES_NEW : Suspends current transaction and creates a new one.
- MANDATORY : Use currently active transaction or throws exception.
- SUPPORTS : Use currently active transaction or execute non-transactional.
- NEVER : Throws exception if there is an active transaction.
- NOT_SUPPORTED : Executes non-transactional whether the current transaction exists or not. If current transaction exists, this will suspend current transaction and execute non-transactional.
- NESTED : Marks a savepoint if there is active transaction or creates a new one if there is no active transaction (like REQUIRED).
Contribute to jskim1991/spring-tx-propagation-test development by creating an account on GitHub.
16. Transaction Management
Traditionally, Java EE developers have had two choices for transaction management: or transactions, both of which have…