Reputation: 41
I am having two datasource one for oracle and other for postgresql and both are used in same business method . How i can make this bussiness method transactional using spring @transaction
Business method
@Transactional
public int getData(){
oracleDao.func1();
postgreDao.func2();
}
In config i have
<bean id="transactionManagerPostGres" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<bean id="transactionManagerOracle" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactoryOracle"/>
</bean>
Upvotes: 4
Views: 3662
Reputation: 403611
You're going to need the support of a proper JavaEE container for this, one that supports two-phase-commit and XA transactions. The Oracle and Postgres JDBC drivers both support XA transactions, so that's OK.
The container exposes this to Spring via the JTA API, and Spring uses that using JtaTransactionManager
. Your application doesn't have to change, it just treats it like a normal transaction.
How you go about setting this up depends entirely on your JavaEE container, each one has a different way of doing it.
Upvotes: 5
Reputation:
Do you mean a two-phase commit? That's a tough problem and depends on the databases and the drivers you use.
Upvotes: 0