0

Currently I have a controller which calls @Transactional annotated method in a service A which inserts the entity to a database, and then calls another method in a service B which updates the entity.

I would like to call only the method in a service A, which will then in turn call a method in a service B. First transaction should happen in a method of a service A, and another transaction should happen in a method of a service B.

I have tried to understand @Transactional annotation, its isolation and propagation in order to achieve this, but I couldn't make it work.

dplesa
  • 1,355
  • 6
  • 23
  • 56

1 Answers1

2

If you want to separate transaction in service B from transaction in service A then you have to start new transaction by using Propagation.REQUIRES_NEW.

Mark your service B method with:

@Transaction(propagation = Propagation.REQUIRES_NEW)
Mạnh Quyết Nguyễn
  • 17,677
  • 1
  • 23
  • 51
  • Spring uses JDBC `Savepoint` under the hood, not all TX supports savepoints, and you need at least JDBC v3.0 and even Oravle 11 doesn't support it: https://stackoverflow.com/questions/10667292/jdbc-check-for-capability-savepoint-release – gavenkoa Jan 17 '20 at 19:32