Proxy Pitfalls & Rollback Semantics
The ways declarative transactions quietly fail: self-invocation, non-public methods, checked exceptions that commit, unexpected rollbacks, lazy loading past the boundary, work on other threads, and pool deadlocks. This is where most real transaction bugs — and most transaction interview questions — come from.
part ofSpring Frameworkoverview, primer and where to startread it →on this pageshowhide
explore
- Self-Invocation Bypass5 questions
- Private/Final Method Limits5 questions
- Checked-Exception Non-Rollback4 questions
- UnexpectedRollbackException5 questions
- Tx Boundary & Lazy Loading5 questions
- Async / New-Thread Tx Boundary Loss5 questions
- REQUIRES_NEW Connection-Pool Deadlock4 questions
questions
page 2 of 2In a large codebase, how would you detect silently-broken self-invoked @Transactional methods, and why does the same trap apply beyond transactions?
basics
~20 sThe same proxy limitation breaks any proxy-based aspect — @Async, @Cacheable, @Retryable, @PreAuthorize — when self-invoked. Detect it by asserting a transaction is active at runtime, code review/static analysis for internal calls to annotated methods, and integration tests that verify rollback/isolation.
When designing transaction boundaries, how do you decide between REQUIRES_NEW, NESTED, and letting exceptions propagate to avoid UnexpectedRollbackException — and what are the correctness trade-offs?
basics
~20 sChoose by atomicity needs: propagate the exception when the whole unit must be all-or-nothing; use REQUIRES_NEW when a sub-operation must commit or fail independently; use NESTED for per-item savepoint rollback within one atomic outer commit. Each has isolation and resource trade-offs.
As a principal engineer, how would you prevent and detect the whole class of 'silently non-transactional method' bugs across a large codebase?
basics
~20 sCombine prevention and detection: keep @Transactional on public non-final methods only, enforce it with static analysis/lint rules, add integration tests that assert rollback, and turn on transaction-interceptor DEBUG logging or startup validation to catch silently-skipped advice.
showing 31–33 of 33