Spring Certified Professional 2023 · Free Practice Question Medium
Question 7
Which transaction propagation behavior uses the current transaction if it exists? (select 2)
-
A
NEVER
-
B
REQUIRED
-
C
SUPPORTS
-
D
REQUIRES_NEW
Reveal correct answers
Correct answers: B, C
Explanation
REQUIRED Propagation ->OK
REQUIRED is the default propagation. Spring checks if there is an active transaction, and if nothing exists, it creates a new one. Otherwise, the business logic appends to the currently active transaction.
SUPPORTS Propagation ->OK
For SUPPORTS, Spring first checks if an active transaction exists. If a transaction exists, then the existing transaction will be used. If there isn't a transaction, it is executed non-transactional.
MANDATORY Propagation ->OK
When the propagation is MANDATORY, if there is an active transaction, then it will be used. If there isn't an active transaction, then Spring throws an exception.
NEVER Propagation ->KO
For transactional logic with NEVER propagation, Spring throws an exception if there's an active transaction.
NOT_SUPPORTED Propagation -> KO
If a current transaction exists, first Spring suspends it, and then the business logic is executed without a transaction.
REQUIRES_NEW Propagation ->KO
When the propagation is REQUIRES_NEW, Spring suspends the current transaction if it exists, and then creates a new one.
NESTED Propagation ->OK
For NESTED propagation, Spring checks if a transaction exists, and if so, it marks a save point. This means that if our business logic execution throws an exception, then the transaction rollbacks to this save point. If there's no active transaction, it works like REQUIRED.
https://www.baeldung.com/spring-transactional-propagation-isolation#transaction-propagations
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
