Home > Enterprise >  Can @Transactional method call another @Transactional method without suspending?
Can @Transactional method call another @Transactional method without suspending?

Time:12-22

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

CodePudding user response:

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.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/support/TransactionTemplate.html

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/transaction/TransactionDefinition.html

https://www.baeldung.com/spring-programmatic-transaction-management#4-custom-transaction-configurations

  • Related