Spring Boot Transaction Management Concepts 5 — Questions and Answers
Question 1: What is the SUPPORTS propagation behavior?
- Requires an existing transaction and suspends it temporarily
- Participates in an existing transaction if one exists; runs without a transaction otherwise (Correct answer)
- Always runs without a transaction, suspending any active one
- Throws an exception if called outside of a transaction
Correct answer: Participates in an existing transaction if one exists; runs without a transaction otherwise
SUPPORTS joins an active transaction if present but executes non-transactionally if no transaction exists, making it flexible for optional transactional context.
Question 2: Which propagation behavior ensures a method always runs WITHOUT a transaction, suspending any existing one?
- NOT_SUPPORTED (Correct answer)
- NEVER
- SUPPORTS
- REQUIRES_NEW
Correct answer: NOT_SUPPORTED
NOT_SUPPORTED suspends any existing transaction and executes the method outside of any transactional context.
Question 3: What is the SERIALIZABLE isolation level's primary trade-off?
- It prevents all anomalies but has the highest performance cost due to extensive locking (Correct answer)
- It allows phantom reads but prevents dirty reads
- It uses optimistic locking exclusively, reducing lock contention
- It is only supported by Oracle databases in Spring Boot
Correct answer: It prevents all anomalies but has the highest performance cost due to extensive locking
SERIALIZABLE prevents all read anomalies (dirty, non-repeatable, phantom) by serializing access, but severely reduces concurrency and throughput.
Question 4: How does Spring Boot enable annotation-driven transaction management automatically?
- By scanning for @Transactional at startup and compiling proxies
- Through TransactionAutoConfiguration which applies @EnableTransactionManagement (Correct answer)
- By requiring the developer to add @EnableTransactionManagement to the main class
- Via a TransactionFilter registered in the Spring Security chain
Correct answer: Through TransactionAutoConfiguration which applies @EnableTransactionManagement
Spring Boot's TransactionAutoConfiguration auto-applies @EnableTransactionManagement when a PlatformTransactionManager bean is detected on the classpath.
Question 5: What happens to the outer transaction if a REQUIRES_NEW inner transaction throws an unchecked exception?
- The outer transaction is always rolled back along with the inner one
- The inner transaction rolls back independently; the outer transaction continues if it catches the exception (Correct answer)
- Both transactions are merged and rolled back together
- Spring creates a compensating transaction to undo the outer transaction's work
Correct answer: The inner transaction rolls back independently; the outer transaction continues if it catches the exception
REQUIRES_NEW transactions are independent — the inner transaction rolls back on its own, and the outer transaction can continue if it catches and handles the exception.
Question 6: In a JTA distributed transaction environment, which Spring transaction manager should be used?
- DataSourceTransactionManager
- JpaTransactionManager
- JtaTransactionManager (Correct answer)
- ChainedTransactionManager
Correct answer: JtaTransactionManager
JtaTransactionManager delegates to the JTA UserTransaction and TransactionManager to coordinate distributed transactions across multiple resources.
Question 7: What is the effect of annotating an interface method with @Transactional in Spring?
- It works identically to annotating the implementing class method
- It is unreliable because Spring's proxy may not detect it depending on the proxy mode (Correct answer)
- It is ignored entirely and must be placed on the concrete class
- It applies the transaction only when the method is called via the interface reference
Correct answer: It is unreliable because Spring's proxy may not detect it depending on the proxy mode
Spring recommends placing @Transactional on concrete classes rather than interfaces because interface-level annotations are not reliably picked up, especially with class-based (CGLIB) proxies.
What is the SUPPORTS propagation behavior?