@Transactional and proxies
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
understand how the annotation works and why it can silently fail.
Planned topics
- Spring wraps your bean in a proxy: begin before the method, commit or rollback after.
- Only calls that go through the proxy get a transaction.
- Self-invocation (
this.other()in the same class) bypasses the proxy, so the annotation onother()is ignored. - Private, package-private, or final-class problems: use public methods on a Spring-managed bean.
- Fix self-invocation by moving the method to another bean.
Draft outline details
Demonstration
public void transfer(...) { debit(...); credit(...); } // called from outside
@Transactional public void debit(...) { ... } // IGNORED when called via this.debit()Check your understanding
Why is @Transactional ignored on a method called with this.?
Show answer
The call skips the proxy.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.