Consider the following service:
The application throws:
java.io.IOException: Inventory service unavailableThe API returns an error.
A. The order insert is rolled back because an exception occurred.
B. The order insert is committed because IOException is a checked exception.
C. Spring automatically retries the transaction.
D. The transaction remains open until the application restarts.
📢 Get actionable Java and Spring Boot insights every week, including practical code tips and real-world, use-case-based interview questions, to help you level up your backend skills—join 8100+ subscribers for hand-crafted, no-fluff content.
Founding Member Offer: Lock in founding member price at $50/year (~$4/month) for life. Limited spot left
Testimonials
B. The order insert is committed because IOException is a checked exception.
A common misconception is:
“Any exception causes a transaction rollback.”
That’s not how Spring works.
By default, Spring rolls back transactions only for:
RuntimeExceptionError
Checked exceptions (such as IOException, SQLException, or any class extending Exception) do not trigger an automatic rollback.
Even though the API fails, the database transaction is committed.

Comments
Nothing yet. Say the first thing.
Sign in to join the conversation.