Example for using two databases w/Spring & JTA transaction manager?
Hi all,
Question for the community. While I've had plenty of occasions to use a single database & single transaction manager with Spring, I've come across a situation where I need to use Spring's JtaTransactionManager with two database connections, and ensure that their transactions are committed atomically. The two databases are both Oracle, but they have completely different schemas & are on completely different servers. Further, I'm not using a traditional JEE container; this is in an OSGi environment, so I'll be using a third party standalone JTA implementation: candidates are Atomikos, JBossTS/Narayana, JOTM and Bitronix.
If I define a single JtaTransactionManager (configured to manage my two Oracle database connections) and use JPA, how do I ensure that I get references to the "right" EntityManager when I need it? Can I write a single DAO that receives transactional injections of two EntityManager instances for the current distributed transaction?
Assume any cross-database references are not persistent object references, but instead are just ids pointing to the object in the other database (for example, a org.example.Foo, stored in the first database, has a field barId that identifies an org.example.Bar in the second database, and vice versa).
Thanks,
Matthew