Issue
Why Spring ChainedTransactionManager is deprecated? Do spring provides any alternative lib to support multiple transaction managers?
My use-case:- We are building a spring boot application that is connected to two data sources let's say (db1 and db2), which performs insert operation on both databases (db1 and db2). And our requirement is something like this : insert -> DB1 -> SUCCESSFUL insert -> DB2 -> ERROR ROLLBACK DB1
Currently, we are using ChaninedTransactionManager and it is working as expected, but I Can see that lib is deprecated? So, just wanted to make sure is it safe to use that, or does Spring provide any alternate lib which we can use as a replacement for this?
Solution
Because there is an API improvement. From the docs https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/transaction/ChainedTransactionManager.html
Instead of using ChainedTransactionManager for attaching callbacks to transaction commit (pre commit/post commit), either register a TransactionSynchronization to explicitly follow transaction cleanup with simplified semantics in case of exceptions.
You are free to still use it, just keep in mind that at some point in the time that class will be removed in future versions of Spring and upgrading will not be possible without refactoring of that part.
Answered By - Antoniossss
Answer Checked By - David Goodson (JavaFixing Volunteer)