Announcement Announcement Module
No announcement yet.
2 queries against different databases Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2 queries against different databases

    I have a method with the following calls to the DAO layer:

    auditDao.capture(user, time, entity, oldValue, newValue); // maps to an insert statement
    In the DAO, I use iBatis. The auditDao maps to an Audit database. The carDao maps to an Automobile database. I want to ensure that if one of the queries fail, then the other does not execute (or is rolled back). How would this best be accomplished using Spring? I'm using Java and Tomcat v6.

    Thanks in advance for your help.
    Last edited by logicg8; Nov 8th, 2011, 10:30 AM.

  • #2
    You need to wrap the statements in the same transaction. If you're using two separate datasources, you'll need to make sure your transaction manager supports XA transactions.


    • #3
      Thanks for the reply arthomps.

      Is there a tutorial that you or someone could recommend on doing this?


      • #4
        I apologize in that I don't have an example readily available.

        There are two key things you need to be sure of. That your transaction manager handles XA transactions and that your datasource is configured as an XADatasource.

        If you're using an application server (weblogic/glassfish/jboss), the odds are pretty high that your have an XA ready transaction manager and you should consult the appropriate application server documentation for datasource configuration options. Alternatively, if you're using a servlet container (tomcat/jetty), you might take a look at atomikos. Their documentation I've found to be very good.