JavaAdvanced#spring

What is @Transactional and how does it work in Spring?

It marks a method or class as requiring a database transaction, managed via a proxy that begins a transaction before the method runs and commits/rolls back afterward based on success or exceptions, respecting the configured propagation and isolation settings.

Example
@Transactional
public void transferFunds(Long from, Long to, double amount) {
  debit(from, amount);
  credit(to, amount); // if this throws, debit() is rolled back too
}

Related Questions

1
JavaBeginner#spring

What is the difference between application.properties and application.yml in Spring Boot?

Open
2
JavaBeginner#spring

What is the purpose of Spring Boot starters?

Open
3
JavaIntermediate#spring

What is the difference between @RequestParam, @PathVariable, and @RequestBody?

Open