Transaction Management — Concept Check
Questions on Transaction Management. @Transactional wraps method execution in a DB transaction; propagation and isolation attributes control nested-transaction and concurrency behaviour.
Questions in this quiz
8 questions on Transaction Management — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.An OrderService method annotated with @Transactional is called from another method within the same OrderService class. What is the likely outcome?
- AThe transaction is not started due to self-invocation.
- BThe transaction starts and commits normally.
- CThe transaction starts only if explicitly configured.
- DThe transaction starts but always rolls back.
2.A developer wants to ensure that audit logs are saved even if the main transaction rolls back. Which propagation setting should they use?
- ASUPPORTS
- BREQUIRES_NEW
- CNESTED
- DREQUIRED
3.What happens if a @Transactional method throws a checked exception and rollbackFor is not specified?
- AThe transaction commits because checked exceptions don't trigger rollback.
- BThe transaction commits only if rollbackFor is set to Exception.class.
- CThe transaction rolls back because all exceptions trigger rollback.
- DThe transaction rolls back only for RuntimeExceptions.
4.A method annotated with @Transactional(readOnly = true) is used to fetch data. What is the advantage of this annotation?
- AIt ensures the transaction is always rolled back.
- BIt automatically commits the transaction faster.
- CIt prevents any exceptions from being thrown.
- DIt skips dirty-checking and flush, optimizing read operations.
5.A service method is slowing down, and logs show frequent transaction rollbacks. What could be a likely cause?
- AChecked exceptions are causing rollbacks, affecting performance.
- BThe method lacks a @Transactional annotation, causing delays.
- CTransactions are committing too frequently, causing delays.
- DUnchecked exceptions are causing rollbacks, affecting performance.
6.Which isolation level should be used to prevent phantom reads in a transaction?
- AREPEATABLE_READ
- BREAD_COMMITTED
- CSERIALIZABLE
- DREAD_UNCOMMITTED
7.A developer uses @Autowired to inject the same bean into itself to fix a self-invocation issue. Why might this be considered an ugly solution?
- AIt relies on Spring's default proxy mechanism, which is not ideal.
- BIt prevents the use of transactions entirely.
- CIt requires additional configuration in application.properties.
- DIt causes the transaction to start twice, leading to errors.
8.What is the default propagation behavior for a @Transactional method if no propagation is specified?
- AREQUIRED
- BREQUIRES_NEW
- CMANDATORY
- DNESTED