Results 1 to 4 of 4

Thread: 2 queries against different databases

  1. #1
    Join Date
    Jul 2006
    Posts
    19

    Default 2 queries against different databases

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

    Code:
    auditDao.capture(user, time, entity, oldValue, newValue); // maps to an insert statement
    carDao.insert(car);
    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 at 10:30 AM.

  2. #2
    Join Date
    Dec 2008
    Location
    New York City
    Posts
    134

    Default

    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.
    Andrew Thompson - Linked In

  3. #3
    Join Date
    Jul 2006
    Posts
    19

    Default

    Thanks for the reply arthomps.

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

  4. #4
    Join Date
    Dec 2008
    Location
    New York City
    Posts
    134

    Default

    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.
    Andrew Thompson - Linked In

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •