In Spring Transaction Management, What is the default propagation level?
* REQUIRED
* SUPPORTS
* MANDATORY
* NEVER
* NOT_SUPPORTED
* REQUIRES_NEW
* NESTED
#spring #certificationquestion #vcp
Answer:
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.
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.
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.
For transactional logic with NEVER propagation, Spring throws an exception if thereโs an active transaction.
NOT_SUPPORTED: If a current transaction exists, first Spring suspends it, and then the business logic is executed without a transaction.
When the propagation is REQUIRES_NEW, Spring suspends the current transaction if it exists, and then creates a new one.
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