Reputation: 1353
I have a Spring application which uses Neo4j graph database and Postgresql relational database. Both databases support transactions.
I have no problems in handling transactions separately on each database using Spring @Transactional annotation with proper transactionManager property.
However I have a plenty of methods manipulating data on neo4j db and postgres db at the same time. Such operations should be transactional so I would like to "merge" those separate transactions. I mean if smth fails on one database engine, then another one should also rollback his own transaction.
Is there any library or tool which can help me achieve that goal? Or do I have to implement it myself?
Thanks in advance!
Upvotes: 3
Views: 481
Reputation: 21883
You can use a ChainedTransactionManager
just like below.
<bean id="transactionManager" class="com.springsource.open.db.ChainedTransactionManager">
<property name="transactionManagers">
<list>
<!-- Postgresql Transaction Manager -->
<bean class="org.springframework.jdbc.datasource.DataSourceTransactionManager"/>
<!-- Neo4J Transaction Manager -->
<bean class="org.neo4j.ogm.session.transaction.TransactionManager"/>
</list>
</property>
</bean>
Upvotes: 2