How to manage different Spring transactions managers

How to manage Two Data source Transaction Managers one for camunda and the other for the application Database?

Given the below transaction managers:

    @Bean(name = "transactionManager")
    @Primary
    public PlatformTransactionManager primaryTransactionManager() {
        return new JpaTransactionManager();
    }

    @Bean(name = "camundaBpmTransactionManager")
    public PlatformTransactionManager camundaTransactionManager(@Qualifier("camundaBpmDataSource") final DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }

The default behavior of rollback is that if the application transaction as an inner transaction fails it will rollback but the camunda transaction as an outer transaction will not be rolled back since each transaction managed by different transaction manager!

Our logic is an atomic unit of work so, for example:
On creating Camunda Task (which is executed by its PlatformTransactionManager), there is a listener which executes an application custom code on different PlatformTransactionManager thus, if our custom application fails, camunda transaction has to rollback the change.

There is a ChainedTransactionManager that could solve most of the multiple transaction managers issues but it’s now deprecated since they discovered that it doesn’t cover all the cases and there are some unexpected behavior. so they deprecated all the feature.

I’m facing a similar issue, did you end up finding a solution?

Follow the instruction in this SO answer