Spring Boot Interview Question - Transactional Trap
Transaction annotation trap in Spring Boot.
Scenario
Consider the following Spring service:
Assume:
Spring’s default transaction configuration
A relational database
No custom rollback rules
Question
What happens when placeOrder() is invoked?
Options
A. The order is saved, the transaction commits, and notification fails
B. The order is NOT persisted because the transaction rolls back
C. No transaction is created at all
D. The application fails at startup
Correct Answer
B. The order is NOT persisted because the transaction rolls back
Explanation
placeOrder()is annotated with@Transactional, so a single transaction is started when the method is entered.saveOrder()is called within the same class, so its own@Transactionalannotation does not create a new transaction. when an@Transactionalmethod, such assaveOrder(), is called from within the same object instance, its annotation is generally ignored because the transaction-intercepting proxy layer is bypassed.sendNotification()throws aRuntimeException.By default, Spring rolls back transactions on unchecked exceptions (
RuntimeException,Error).Since everything runs inside the same transaction, the database changes made by
saveOrder()are rolled back.
Result: No order is persisted.
Spring uses proxy-based AOP. Self-invocation bypasses the proxy, so the inner annotation is ignored.
📢 Get actionable Java/Spring Boot insights every week — from practical code tips to real-world use-case based interview questions.
Join 5100+ subscribers and level up your Spring & backend skills with hand-crafted content — no fluff.
First 100 paid subscribers will get the annual membership at $50/year ( 61 already converted to paid, 39 remaining )
Not convinced? Check out the details of the past work
What if
sendNotification()is moved to another Spring bean?
Yes, the transaction would still roll back — by default.




