Back to feed
Dev.to
Dev.to
7/8/2026
The original headline is: "2 @Transactional Traps That Catch Even Senior Java Developers in interviews"

The original headline is: "2 @Transactional Traps That Catch Even Senior Java Developers in interviews"

Original: 2 @Transactional Traps That Catch Even Senior Java Developers in interviews

Short summary

A senior Java developer shares two common @Transactional pitfalls that trip up experienced engineers in interviews. First, calling a @Transactional method from within the same class bypasses Spring's proxy wrapper, so no transaction is applied. Second, @Transactional only rolls back on unchecked exceptions by default, meaning checked exceptions like RefundException will allow the transaction to commit despite failures. Both bugs can silently corrupt data in production.

  • Self-invocation of @Transactional methods skips Spring's proxy, so no transaction runs
  • By default only unchecked exceptions trigger rollback; use rollbackFor = Exception.class for checked exceptions
  • Both issues pass tests but cause partial data updates in production

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Comments

Failed to load comments. Please try again.

Explore more