I have to update two data sources as part of one transaction. That is -
If upd
The best way is to create a third method, that will be annotated as @Transactional.
@Transactional(readOnly = false)
public void updateCommon(){
upbateDb01();
upbateDb02();
}
According to a spring documentation, transaction control starts when the firts annotation appears,so in this case a single transaction will start when updateCommon will be invoked.
UPDATE
But this will work if you use CrudRepository or something like that.
In case of multiple datasources you may try to use a Global transaction management conception. Here is a sample from a spring documentation:
@Inject private PlatformTransactionManager txManager;
TransactionTemplate template = new TransactionTemplate(this.txManager);
template.execute( new TransactionCallback
And here is a link: http://spring.io/blog/2011/08/15/configuring-spring-and-jta-without-full-java-ee/ I have never use it for my own, so I didn't explore this topic deeply. Hope it will help