I have method A and method B in different classes. Both are annotated with @Transactional. Method A is calling B. Is there any solution to call B in different transaction but without suspending A transaction? Propagation.REQUIRES_NEW on B gives the possibility to always create new transaction when it's called but is suspends the caller transaction
2 Answers
As far as i know you can't do it with annotation REQUIRED_NEW.
But spring also support transaction manually with TransactionTemplate, TransactionDefinition.
we can use multiple definitions with just one PlatformTransactionManager.

- 1,931
- 1
- 11
- 11
-
i think the problem may be in approach. Instead of trying to find how to call method in different transaction without suspending caller transaction i need to take out the method call from caller transaction – SurPrise 2 Dec 22 '21 at 09:30
-
Yes, simplify the code is the best way, i just want to answer "can we call functionB without suspending transaction of functionA ...", it's possible ... but quite complicated then necessary – Huy Nguyen Dec 22 '21 at 09:33
Transaction propagation behaviour Propagation.NESTED supports the requirement.
Do read through the Spring official documentation : Understanding PROPAGATION_NESTED
PROPAGATION_NESTED uses a single physical transaction with multiple savepoints that it can roll back to. Such partial rollbacks let an inner transaction scope trigger a rollback for its scope, with the outer transaction being able to continue the physical transaction despite some operations having been rolled back.
Additional details on the nested propagation in Spring transactions can be read in this answer as well.

- 6,436
- 3
- 19
- 28