In Spring Transaction Management, What is the default propagation level?
#spring #certificationquestion #vcp
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.