Blog

Your dream job? Lets Git IT.
Interactive technical interview preparation platform designed for modern developers.

XGitHub

Platform

  • Categories

Resources

  • Blog
  • About the app
  • FAQ
  • Feedback

Legal

  • Privacy Policy
  • Terms of Service

© 2025 LetsGit.IT. All rights reserved.

LetsGit.IT/Categories/Spring
Springmedium

How does `@Transactional` work (rollback + common gotcha)?

Tags
#transaction#transactional#rollback
Back to categoryPractice quiz

Answer

It runs the method inside a transaction; by default Spring rolls back on unchecked (`RuntimeException`) errors. A common gotcha is self-invocation: calling a `@Transactional` method from the same class bypasses the proxy, so the transaction may not start.

@Service
class PaymentService {
  @Transactional
  public void pay() {
    // DB writes here
  }
}

Related questions

Spring
Transaction propagation in Spring — what does `REQUIRED` mean?
#transaction#propagation#spring
Spring
Spring AOP proxies — what is the self-invocation problem?
#aop#proxy#transactional
Spring
How does @Transactional work?
#transaction#aop#database
Monoliths
How do you introduce a breaking database change safely in a large monolith?
#db-migration#expand-contract#deployment
Databases
What is a transaction and why do we use it?
#transaction#acid#consistency