Spring @Transactional with a transaction across multiple data sources

I’ve solved this problem using ChainedTransactionManager – http://docs.spring.io/spring-data/commons/docs/1.6.2.RELEASE/api/org/springframework/data/transaction/ChainedTransactionManager.html Spring Boot Configuration: @Bean(name = “chainedTransactionManager”) public ChainedTransactionManager transactionManager(@Qualifier(“primaryDs”) PlatformTransactionManager ds1, @Qualifier(“secondaryDs”) PlatformTransactionManager ds2) { return new ChainedTransactionManager(ds1, ds2); } And then you can use it as follows: @Transactional(value=”chainedTransactionManager”) public void updateDb01() { Entity01 entity01 = repository01.findOne(1234); entity01.setName(“Name”); repository01.save(entity01); //Calling method to update DB02 updateDb02(); } public … Read more

Spring – Is it possible to use multiple transaction managers in the same application?

Where you use a @Transactional annotation, you can specify the transaction manager to use by adding an attribute set to a bean name or qualifier. For example, if your application context defines multiple transaction managers with qualifiers: <bean id=”transactionManager1″ class=”org.springframework.orm.jpa.JpaTransactionManager”> <property name=”entityManagerFactory” ref=”entityManagerFactory1″ /> <qualifier value=”account”/> </bean> <bean id=”transactionManager2″ class=”org.springframework.orm.jpa.JpaTransactionManager”> <property name=”entityManagerFactory” ref=”entityManagerFactory2″ /> <qualifier … Read more