Transaction Propagation — Concept Check
Questions on Transaction Propagation. REQUIRED (default, join or create), REQUIRES_NEW (always new, suspends outer), NESTED, SUPPORTS, NOT_SUPPORTED, MANDATORY, and NEVER — choose based on desired transactional boundary.
Questions in this quiz
8 questions on Transaction Propagation — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.When a method annotated with @Transactional(propagation = Propagation.REQUIRES_NEW) is called within an existing transaction, what happens?
- AAn exception is thrown if an existing transaction is found.
- BA new transaction starts, suspending the existing one.
- CThe existing transaction is joined by the new method.
- DThe method runs non-transactionally, ignoring the existing transaction.
2.A service method annotated with @Transactional is called, but no existing transaction is present. What propagation behavior is expected by default?
- AA new transaction is created.
- BThe method runs non-transactionally.
- CAn exception is thrown due to missing transaction.
- DThe method waits for a transaction to start.
3.In a scenario where audit logging must persist even if the main business transaction fails, which propagation type should be used for the logging method?
- ASUPPORTS
- BREQUIRED
- CMANDATORY
- DREQUIRES_NEW
4.A method with @Transactional(propagation = Propagation.NESTED) throws an exception. What is the effect on the outer transaction?
- AThe outer transaction is suspended until resolved.
- BOnly changes since the savepoint are rolled back.
- CThe exception is ignored, and the transaction continues.
- DThe entire outer transaction is rolled back.
5.What happens if a method annotated with @Transactional(propagation = Propagation.MANDATORY) is called without an active transaction?
- AThe method execution is skipped.
- BAn IllegalTransactionStateException is thrown.
- CThe method runs non-transactionally.
- DA new transaction is automatically started.
6.A developer uses this.charge() within the same bean to call a method with @Transactional(propagation = Propagation.REQUIRES_NEW). What is the issue?
- AThe transaction type changes to REQUIRED.
- BThe method runs twice due to proxy behavior.
- CThe transaction is correctly applied.
- DThe transaction is ignored due to self-invocation.
7.Why might a @Transactional method with propagation SUPPORTS not run in a transaction?
- AIt always requires a new transaction to run.
- BIt runs non-transactionally by default.
- CIt joins an existing transaction if present, otherwise runs non-transactionally.
- DIt throws an exception if no transaction is present.
8.A method with @Transactional(propagation = Propagation.NEVER) is mistakenly called within a transaction. What happens?
- AThe method joins the existing transaction.
- BAn exception is thrown because it must not run in a transaction.
- CA new transaction is started for the method.
- DThe method runs non-transactionally, ignoring the existing transaction.