28

Is it possible to nest @Transactional annotated methods in spring? Consider something like this:

@Transactional
public void a() {
    obj.b();
}

@Transactional
public void b() {
    // ... 
}

What happens in such a case if I rollback in b() and rollback in a() ?

Erik
  • 11,944
  • 18
  • 87
  • 126

1 Answers1

47

The second @Transactional annotation on method b() is not required because by default @Transactional has a propagation of REQUIRED, therefore methods called by method a() will be transactional. If you are looking to start a new transaction within a method called by method a() you will need to modify the propagation rules. Read about Transaction Propagation.

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189