Scrivio Interview library
LeadershipAdvanced5 min read · updated 12 November 2026

Bugs from committed partial data after checked exceptions keep appearing in Java and Kotlin services. Would you change the rollback default for the organisation, and how?

Yes, I would move the organisation to rolling back on all exceptions, because that is what most developers already expect, and Kotlin developers have no checked exceptions to remind them otherwise. Spring Framework 6.2 offers a global setting for this through @EnableTransactionManagement (check your version); on older versions we use rollbackFor = Exception.class consistently, ideally through a composed annotation. Because changing the default alters behaviour in existing services, I would roll it out with tests on exception paths, make it the default in the shared starter for new services, and document the rule so reviewers can check it.

Why this question is asked

When the same bug appears again and again across teams, it is rarely a problem with individual developers; it is a sign that the default does not match how people think. Spring's rule of committing on checked exceptions is a clear example: it made sense for EJB-era Java, it is invisible in Kotlin, and it silently leaves partial data behind. Interviewers ask a leadership question like this to see whether we can change a platform-wide default safely, weighing consistency against the risk of breaking working systems. In this answer, we will look at why the current default causes these bugs, the options for changing it, how to roll it out to existing services without surprises, and how to make the rule stick.

1Why the Current Default Keeps Causing Bugs

By default, a @Transactional method rolls back on RuntimeException and Error and commits on checked exceptions. The convention came from EJB, where checked exceptions were meant to be business outcomes the caller handles, with the work so far still valid. In practice most developers expect the opposite: if a method fails, its work is undone. So when an IOException or a custom checked exception is thrown halfway through, rows that the developer believes were rolled back stay in the database.

Kotlin makes this worse. Kotlin has no checked exceptions, so a Kotlin developer sees nothing in the code that marks IOException as different from IllegalStateException, yet Spring still decides by the Java class hierarchy. In an organisation with both languages, the bug keeps returning because the language gives no hint.

Java
// Kotlin: nothing here suggests the two rows will be committed
@Transactional
fun importBatch(file: Path) {
repository.save(Batch("B-1"))
repository.save(Batch("B-2"))
Files.readString(file) // throws NoSuchFileException (checked in Java): COMMIT
}

2The Options for Changing the Default

Spring Framework 6.2 added a global switch: @EnableTransactionManagement(rollbackOn = RollbackOn.ALL_EXCEPTIONS) makes every @Transactional method roll back on any exception unless it says otherwise. This is the cleanest option because developers keep writing a plain @Transactional and get the expected behaviour. Check your version for the exact attribute and how Spring Boot exposes it.

On older versions, the options are per method: rollbackFor = Exception.class on every annotation, which is easy to forget, or a composed annotation that carries it, which is easy to check.

Java
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(rollbackFor = Exception.class)
public @interface UseCase {} // teams write @UseCase instead of @Transactional
// Spring Framework 6.2+, in the shared starter (check your version):
@EnableTransactionManagement(rollbackOn = RollbackOn.ALL_EXCEPTIONS)

Either way, individual methods can still opt out with noRollbackFor when committing on a specific exception really is intended, which makes that rare case explicit instead of accidental.

3Why Changing It in Existing Services Is Risky

Some existing code depends on the current default, knowingly or not. A method may throw a checked exception precisely so that its partial work is kept, for example a batch job that saves progress and then signals a recoverable problem. Flip the global default and that work starts disappearing. Because the change is invisible in the code, it would look like a mysterious data loss after a routine dependency upgrade.

So I would treat it as a behaviour change, not a configuration tweak, and roll it out service by service.

Step throughRolling out the new default to one service
  1. List methods that can throw checked exceptionsstatic search or ArchUnit
  2. Add tests that assert database state on those pathsthey pass with today's behaviour
  3. Does any path rely on commit after a checked exception?
    YesMark it noRollbackFor, explicitlyNoGo on
  4. Turn on the setting, update the expected state in tests
  5. Release, watch error and data-repair metrics

5 steps in order. Play them, or step through them one at a time.

4Making It the Default for New Services

For new services there is no existing behaviour to protect, so the setting goes into the shared Spring Boot starter that every service uses: the auto-configuration enables the global rollback rule, or, on older Spring versions, the starter provides the @UseCase annotation and an ArchUnit rule that forbids plain @Transactional without rollbackFor. New services get the safe behaviour without anyone deciding it again.

Putting it in the starter also gives a single place to change it later, and a version number that tells us which services have adopted it.

5Documenting the Rule So Reviewers Can Check It

A rule that only lives in a starter is invisible to reviewers. I would write it down in one short paragraph in the engineering guidelines: transactions roll back on any exception; committing after an exception requires an explicit noRollbackFor with a comment saying why. Reviewers then have a concrete question to ask on every pull request that touches transactions.

Finally, I would close the loop with the people who reported the bugs: share the incidents that motivated the change, show the test pattern for exception paths, and track whether the 'partial data after exception' class of incident goes away over the next quarters.

6Follow-up questions

Would you change the default everywhere at once with a dependency bump?

No. Even though it is one line of configuration, it changes behaviour of code nobody is looking at. I would make the starter offer it as an opt-in first, adopt it service by service with tests, and only make it the starter default once the main services have moved.

What about services that handle checked exceptions deliberately?

They keep that behaviour by declaring noRollbackFor on the methods where commit-after-exception is intended. That turns an implicit, easy-to-miss convention into an explicit and reviewable choice.

Is rolling back on all exceptions ever wrong?

It is wrong when a method's partial work is valid on its own and the exception signals a condition for the caller. Those cases exist, but they are rare, and making them explicit is better than making the common case dangerous.

7Conclusion

In this answer, we saw that Spring's commit-on-checked-exception default contradicts what most developers expect and is invisible in Kotlin, which is why partial-data bugs keep appearing. I would move to rolling back on all exceptions, through the Spring Framework 6.2 global setting where available or a composed annotation with rollbackFor = Exception.class, roll it out to existing services with tests on exception paths, make it the default in the shared starter for new services, and document the rule for reviewers.

What to say in the interviewAbout 90 seconds aloud

Open with

I would change it, but carefully. The current default, roll back on runtime exceptions and commit on checked ones, comes from EJB and doesn't match what most developers expect, which is that if a method fails its work is undone.

Then, if they want more

In Kotlin it's even less visible, because there are no checked exceptions, so nothing in the code tells you an IOException will commit. That's why the same bug keeps appearing across teams. On Spring Framework 6.2 or later there's a global setting on @EnableTransactionManagement to roll back on all exceptions, and I'd check the exact attribute for our version.

On older versions I'd use a composed annotation, say @UseCase, that carries rollbackFor = Exception.class, and an ArchUnit rule that flags plain @Transactional. The risk is existing services: some code may rely on committing after a checked exception, and flipping the default silently changes that.

So for existing services I'd roll it out one by one, first adding tests that assert the database state on every exception path, marking any intentional commit-after-exception with an explicit noRollbackFor, then enabling the setting. For new services I'd put it in the shared starter so they get it by default.

And I'd document the rule in our guidelines, that commit after an exception needs an explicit noRollbackFor with a reason, so reviewers can check it, and track whether that class of incident disappears.

About this answer

Last updated
12 November 2026
Versions it names
Spring Framework 6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Bugs from committed partial data after checked exceptions keep appearing in Java and...": https://scrivio-interview-library.netlify.app/databases/transactions/1426991c52/