skip to content

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 pageshow

explore

questions

page 2 of 2

In a large codebase, how would you detect silently-broken self-invoked @Transactional methods, and why does the same trap apply beyond transactions?

level: principalimportance: should knowfreq 30%

basics

~20 s

The 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.

open as a page

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?

level: principalimportance: should knowfreq 30%

basics

~20 s

Choose 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.

open as a page

As a principal engineer, how would you prevent and detect the whole class of 'silently non-transactional method' bugs across a large codebase?

level: principalimportance: nice to knowfreq 22%

basics

~20 s

Combine 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.

open as a page

showing 31–33 of 33