@Transactional Behaviour — Concept Check
Questions on @Transactional Behaviour. @Transactional creates or joins a transaction on method entry and commits (or rolls back on unchecked exception) on exit; proxying means self-invocation bypasses the advice.
Questions in this quiz
8 questions on @Transactional Behaviour — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer notices that a @Transactional method is not rolling back on a checked exception. What could be the issue?
- AThe exception is not propagated out of the method
- BChecked exceptions do not trigger rollback by default
- CThe transaction is not managed by Spring
- DThe method is missing the rollbackFor attribute
2.What happens when a @Transactional method is called from another method within the same class?
- AThe transaction is managed correctly by Spring
- BA new transaction is created for each call
- CThe method throws an exception due to proxy issues
- DThe transaction is bypassed due to self-invocation
3.A service method annotated with @Transactional(readOnly = true) is used to fetch data. What is a potential benefit?
- AEnsures data consistency across transactions
- BImproves transaction isolation level
- CSkips dirty checking and flush before commit
- DAutomatically rolls back on all exceptions
4.Why might a Hibernate Session be closed unexpectedly after a @Transactional method completes?
- AThe Session is not properly initialized
- BThe transaction commits and the Session is closed
- CA checked exception was thrown
- DThe method was called from a non-transactional context
5.A developer adds @Transactional to a method but notices no transaction management occurs. What might be the cause?
- AThe transaction manager is not configured
- BThe method is private
- CThe method has a void return type
- DThe method is called directly within the same bean
6.What is the default behavior of Spring transactions when a RuntimeException is thrown?
- AThe transaction is committed
- BThe transaction is rolled back
- CThe transaction is ignored
- DThe transaction is paused
7.A developer uses @Transactional(noRollbackFor = DuplicateOrderException.class). What does this configuration imply?
- AOnly RuntimeExceptions will trigger a rollback
- BChecked exceptions will trigger a rollback
- CAll exceptions will trigger a rollback
- DDuplicateOrderException will not trigger a rollback
8.How does Spring handle transactions for repository operations within a @Transactional method?
- AEach operation opens a new transaction
- BAll operations share the same Session and transaction
- COperations are executed without a transaction
- DEach operation uses a separate Session