The 30 second answer
There are three usual causes. By default Spring rolls back only on unchecked exceptions and errors, so a checked exception still commits unless I set rollbackFor. Second, the exception was caught inside the method and never rethrown. Third, self-invocation: calling a transactional method from the same class skips the proxy, so no transaction is started for that call.
Three common causes. One: by default Spring rolls back only on unchecked exceptions (RuntimeException and Error), not checked ones; fix with rollbackFor = Exception.class. Two: the exception was caught inside the method and not rethrown. Three: self-invocation; calling a @Transactional method from the same class skips the proxy, so no transaction starts on that call. Follow-up: How do you fix self-invocation? (Move the method to another bean, or inject the proxy; the docs suggest AspectJ mode as an alternative.)
Alternate interview scenarios
"A @Transactional operation partially fails. Why might the rollback not happen as expected?"
In this version, some of the changes stay even though the operation failed. The three causes above still apply. There are also three more. First, a method with REQUIRES_NEW runs in its own independent transaction, so its work is already committed when the outer transaction rolls back. Second, the rollback only covers resources that the transaction manager controls. A file write, an HTTP call or a message sent outside a transactional producer stays done, and I move that work to an after-commit listener or an outbox. Third, if an inner transactional call fails and the caller catches the exception, the shared transaction is marked rollback-only, and the outer commit throws UnexpectedRollbackException.
"@Transactional on a private method. Why does it silently fail?"
Here no transaction ever starts, which is different from a rollback that doesn't happen. In the default proxy mode, Spring adds transactions by wrapping the bean in a proxy, and the proxy can only intercept calls that come from outside the bean. A private method can't be overridden by a class-based proxy, and the only way to reach it is from inside the same object, so the annotation is simply ignored, with no error. Each statement then runs in auto-commit, so a failure halfway leaves partial writes. Since Spring Framework 6.0, protected and package-visible methods can also be transactional with class-based proxies, but private methods still cannot. The fix is to put the annotation on a public method of another bean that the caller injects, or to switch to AspectJ weaving. To check it, I enable debug logging for the transaction manager and look for the transaction being created.
"When can @Transactional fail to apply?"
This prompt is about advice that never runs, so there is no transaction boundary, not about a transaction that started and then committed anyway. Besides a private method, I look for a self-invocation (this.save()), a final method that a class-based proxy cannot advise, a call on an object created with new rather than a Spring-managed bean, and a JDK interface proxy where the method is not on the interface. I also confirm a transaction manager is actually configured: if the proxy runs and no PlatformTransactionManager (or ReactiveTransactionManager) is present, the call fails with a bean or transaction-manager error rather than silently auto-committing. Debug logging on the transaction manager shows whether a transaction was started. The fix is to put the annotation on a public method of a Spring bean that the caller injects, or to use TransactionTemplate or AspectJ weaving.
Sources (4)
- Spring: Using @Transactional (proxy, self-invocation and method visibility)docs.spring.io
- Spring: Rolling back a declarative transactiondocs.spring.io
- Spring: Transaction propagation (REQUIRED, REQUIRES_NEW, rollback-only)docs.spring.io
- Spring: Transaction-bound events (@TransactionalEventListener)docs.spring.io