Return to site

๐Ÿƒ๐ŸŽ“ SPRING CERTIFICATION QUESTION: In Spring Transaction Management, What is the default propagation level?

September 15, 2023

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