Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

In a Spring service, @Transactional on a method has no effect when the method is called from another method in the same class. Explain using how proxies work and give fixes.

Spring applies @Transactional through a proxy that wraps the bean, and the transaction logic runs only when a call enters through that proxy. A call such as this.recordAudit() inside the bean goes to the real object directly, so the transaction interceptor never runs and the annotation's settings are ignored. The fixes are to move the method to another bean, call the bean's own proxy, or manage the transaction explicitly with TransactionTemplate; AspectJ weaving also works because it changes the bytecode instead of wrapping the reference. Private and final methods are not intercepted by subclass proxies either.

Why this question is asked

This bug rarely shows up as an error. The code compiles, the annotation is right there, and the method runs; only the transaction behaviour is missing, so the symptom appears much later as missing audit rows, partial updates or data that should have been rolled back. Interviewers ask it because explaining it requires knowing how Spring builds proxies, which is the same mechanism behind @Async, @Cacheable and method security. In this answer, we will recap how the proxy is built, reproduce the bug with an audit record that disappears, see why the self-call skips the proxy, go through the fixes, and cover private and final methods and how to catch this in review.

1A Quick Recap: The Proxy Around Every Transactional Bean

When Spring creates a bean whose class has @Transactional methods, it does not hand our object to other beans. It creates a proxy, a generated object with the same type, and injects that instead. In Spring Boot the proxy is by default a CGLIB subclass of our class, generated at run time, with a name like PaymentService$$SpringCGLIB$$0. Each overridden method in the subclass asks the transaction interceptor to begin, join or suspend a transaction according to the annotation, then calls the same method on our real object, which is a separate instance held inside the proxy.

So there are two objects: the proxy that other beans hold, and the target, our real PaymentService. Everything the annotation promises happens in the proxy, before and after the call reaches the target.

2Reproducing the Bug: The Audit Row That Disappears

Suppose a refund must always leave an audit record, even when the refund itself fails and rolls back. The developer puts the audit in its own transaction with REQUIRES_NEW, which should suspend the outer transaction and commit the audit independently.

Java
@Service
public class PaymentService {
@Transactional
public void refund(long paymentId) {
recordAudit(paymentId, "refund requested"); // really this.recordAudit(...)
payments.markRefunded(paymentId);
gateway.refund(paymentId); // throws GatewayException
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void recordAudit(long paymentId, String event) {
audits.save(new Audit(paymentId, event));
}
}
// paymentService.refund(7) with the gateway failing:
// GatewayException: card network unavailable
// SELECT count(*) FROM audit WHERE payment_id = 7; -- 0, the audit row was rolled back too

Notice that the audit row is gone. REQUIRES_NEW was never applied: recordAudit() simply ran inside refund()'s transaction, so when refund() rolled back, the audit insert rolled back with it. If refund() had no @Transactional at all, recordAudit() would have run with no transaction of its own, which is the other common form of the same bug.

3Why the Self-Call Skips the Proxy

The controller calls refund() on the proxy, so the interceptor starts a transaction and forwards the call to the real PaymentService. Inside the real object, recordAudit(paymentId, ...) is shorthand for this.recordAudit(...), and this is the real object, not the proxy. A plain Java call on this goes straight to the method's code. The proxy, the only place that reads @Transactional, never sees the call, so it cannot suspend the outer transaction and start a new one.

This is not a Spring bug; it is how wrapping works. A wrapper can only intercept calls that come through the wrapper. The same is true for every annotation Spring applies through proxies: @Async, @Cacheable, @Retryable and @PreAuthorize all do nothing on a self-call.

Step throughrefund() calling recordAudit() on this
ControllerPaymentService proxyPaymentServiceDatabase
refund(7)
begin transaction T1
refund(7)
this.recordAudit(7): no proxy, stays in T1
insert audit (in T1)
GatewayException
roll back T1: audit row lost too

7 messages in order. Play them, or step through them one at a time.

The REQUIRES_NEW setting is never read, because the proxy never sees the call.

4Fix 1: Move the Method to Another Bean

The clearest fix is to put recordAudit() in its own bean. The call then leaves PaymentService and enters AuditWriter through AuditWriter's proxy, which reads REQUIRES_NEW and does what we asked.

Java
@Service
class AuditWriter {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void record(long paymentId, String event) { audits.save(new Audit(paymentId, event)); }
}
@Service
public class PaymentService {
private final AuditWriter audit;
PaymentService(AuditWriter audit) { this.audit = audit; }
@Transactional
public void refund(long paymentId) {
audit.record(paymentId, "refund requested"); // through AuditWriter's proxy: own transaction, committed
payments.markRefunded(paymentId);
gateway.refund(paymentId); // throws, rolls back only the refund
}
}
// SELECT count(*) FROM audit WHERE payment_id = 7; -- 1

It also improves the design, because auditing is a separate responsibility with its own transaction rule, and anyone reading PaymentService can now see that.

5Fix 2 and 3: The Bean's Own Proxy, or TransactionTemplate

If moving the method is not practical, we can call through the proxy ourselves. Injecting the bean into itself, lazily so Spring can resolve the cycle, gives us a reference to the proxy. Spring also offers AopContext.currentProxy(), but only when proxy exposure is switched on with @EnableAspectJAutoProxy(exposeProxy = true), and it ties our code to Spring AOP, so it is rarely the best choice.

Alternatively we can drop the annotation for that piece and run it in a transaction explicitly with TransactionTemplate, which does not depend on proxies at all.

Java
// self-injection: works, but hides the reason from the next reader
@Autowired @Lazy private PaymentService self;
self.recordAudit(paymentId, "refund requested"); // goes through the proxy
// TransactionTemplate: explicit and proxy-free
private final TransactionTemplate requiresNew;
PaymentService(PlatformTransactionManager tm) {
requiresNew = new TransactionTemplate(tm);
requiresNew.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
}
requiresNew.executeWithoutResult(s -> audits.save(new Audit(paymentId, "refund requested")));

There is one more option: AspectJ weaving, enabled with @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) plus the spring-aspects library and compile-time or load-time weaving. AspectJ inserts the transaction code into our class's bytecode itself, so there is no separate proxy reference and self-calls are intercepted. It solves the problem completely but adds a weaving step to the build or a Java agent at startup, which many teams prefer to avoid.

6Private and Final Methods Are Not Intercepted Either

The CGLIB proxy is a subclass that overrides our public methods. It cannot override a private method, so @Transactional on a private method is ignored even when called from another bean. A final method is worse. The subclass cannot override it, so the call runs our method's code on the proxy instance itself. The proxy object was created without running our constructor and has no injected fields, so the method often fails with a NullPointerException on a dependency that is clearly injected in the real bean. Static methods are not intercepted either. Keep transactional methods public and non-final.

7Follow-up questions

How would you detect this in code review?

I look for any method with @Transactional, @Async, @Cacheable or a security annotation that is called from another method of the same class without a bean reference in front of it, and for annotations on private or final methods. Some IDEs flag self-invocation of proxied methods, and an ArchUnit rule or a static analysis check can enforce it. In tests, asserting TransactionSynchronizationManager.isActualTransactionActive() inside the method, or enabling TRACE logging for org.springframework.transaction.interceptor, which logs each transaction the interceptor gets, shows quickly whether the proxy ran.

Does @Transactional on the class instead of the method help?

No. It applies the settings to every public method, but a self-call still never passes through the proxy. The rule is about where the call comes from, not where the annotation is.

Would a JDK interface proxy behave differently?

Not for self-calls. With a JDK proxy the bean is reached through its interface, and this inside the implementation is still the real object, so the same calls skip the proxy. The difference is only in what can be intercepted from outside: a JDK proxy intercepts interface methods only.

8Conclusion

In this answer, we saw that Spring applies @Transactional through a proxy wrapping the bean, so only calls that enter through the proxy get transaction behaviour. A this.method() call inside the bean goes straight to the real object, which is why REQUIRES_NEW was ignored and the audit row was rolled back. Moving the method to another bean is the cleanest fix, with self-injection and TransactionTemplate as alternatives and AspectJ weaving for self-calls in general, and private and final methods are never intercepted by subclass proxies.

What to say in the interviewAbout 80 seconds aloud

Open with

Spring implements @Transactional with a proxy. Other beans hold the proxy, usually a CGLIB subclass in Spring Boot, and its overridden methods ask the transaction interceptor to start, join or suspend a transaction before calling the real object.

Then, if they want more

When a method in the bean calls another method of the same bean, that's a call on this, the real object, so it never goes through the proxy and the annotation on the inner method is just ignored.

For example, if refund is transactional and calls recordAudit marked REQUIRES_NEW, the audit runs inside refund's transaction and gets rolled back with it. The fix I prefer is moving the inner method to its own bean, so the call goes through that bean's proxy; it also makes the transaction boundary visible in the design.

Alternatives are injecting the bean's own proxy lazily, or using TransactionTemplate to run that part explicitly. AspectJ weaving also intercepts self-calls, because it changes the class's bytecode rather than wrapping the reference, but it adds a weaving step.

Private methods aren't intercepted by the subclass proxy, and final methods are worse, since they run on the proxy instance where injected fields are null. In review I watch for annotated methods called without a bean reference, and in tests I check isActualTransactionActive.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "In a Spring service, @Transactional on a method has no effect when the method is called...": https://scrivio-interview-library.netlify.app/java/reflection-and-method-handles/a6f24dc268/