Engineering With Java

Engineering With Java

Spring Boot Interview Question - Transactional Trap

Transaction annotation trap in Spring Boot.

Suraj Mishra's avatar
Suraj Mishra
Feb 17, 2026
∙ Paid

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 @Transactional annotation does not create a new transaction. when an @Transactional method, such as saveOrder(), is called from within the same object instance, its annotation is generally ignored because the transaction-intercepting proxy layer is bypassed.

  • sendNotification() throws a RuntimeException.

  • 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 )

So far we have covered 44+ real world based interview questions and will add up to 100 by end of this year.

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.

User's avatar

Continue reading this post for free, courtesy of Suraj Mishra.

Or purchase a paid subscription.
© 2026 Suraj Mishra · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture