workOwonworkOwonA New Way to Connect
HomeFeedJobsCommunitiesEventsFeaturesAbout workOwon
HomeFeedJobsCommunitiesEventsFeaturesAbout workOwon
HomeCommunitiesJava & Spring Developers India

Spent 2 hours on this today. My service method throws a custom checked exception after saving an entity, an…

DJ

Dhruv Joshi

Software Developer | Java, Spring Boot, React | Learning system design one outage at a time

1 Oct 2026· Java & Spring Developers India

Spent 2 hours on this today. My service method throws a custom checked exception after saving an entity, and the save is NOT rolled back. ```java @Transactional public void createInvoice(...) throws InvoiceException { repo.save(invoice); if (bad) throw new InvoiceException("..."); } ``` Is this expected? Feels like a bug.
7 reactions3 comments

Comments

  • AS

    Aarav Sharma1 Oct 2026

    Expected! By default Spring only rolls back on RuntimeException and Error. Use @Transactional(rollbackFor = InvoiceException.class) or make it extend RuntimeException.

  • RM

    Rohan Malhotra1 Oct 2026

    This one bites everyone once. I'd lean towards unchecked exceptions for business errors in Spring apps, it keeps the default behavior sane.

  • DJ

    Dhruv Joshi1 Oct 2026

    Wow, that was it. Thank you both! Switched to RuntimeException.

Join the conversation

Join workOwon to react, comment and follow people and communities you care about.

Log inJoin now

Popular communities

See all