1 Reply Latest reply on Apr 17, 2013 6:12 AM by gimbal2

    XA Connection concept

      . Why do we need XA connection ? I am not able to find a logical reason behind it.

      If I user normal connections for e.g.

      First Algo

      Connection1= connection TO Datbase1
      Connection2= connection To Database 2
      Insert something into Databse1
      Insert something into Database2
      }Catch(Any SQLException)
      Second Algo

      Now if I use XA Connection
      XAConnection1= connection TO Datbase1
      XAConnection2= connection To Database 2
      Connection1= Connection1 from XAConnection1
      Connection2= Connection2 from XAConnection2
      XAResource1=Resource from XAConnection1;
      XAResource2=Resource from XAConnection2;
      XID1=For XAConnection1 Transaction
      XID2=For XAConnection2 Transaction
                Start transaction for Resource1          
      Insert something into Databse1 using 
                End Transaction
      Start transaction for Resource2
      Insert something into Database2
                End Transaction
      If (OK=XAResource1.prepare for XID1 && OK=XAResource2.prepare)
           Commit Both
           Rollback Both;
      }Catch(Any SQLException)
           Rollback all transactions
      Now this is pretty similar to First Algo : suppose the insert for Databsae 2 fails , then it goes into sql exception block and we roll back both . Now in second case too if the second insert leads up to exception it still goes to exception block and the condition to check the Resource1.prepare might never be encountered and by default it gets rolled back ( as nothing gets committed).

      I am not able to convince myself that why should I go for expensive XA connection and over work where I can tweak the normal connection paradigm to achieve almost the same thing.

      I even thought what would happen in case of remote calls like EJB , but I realized that its completely out of topic to this .

      I understand XA connection is general topic not limited to Databases but if I am only dealing with Database for instance , then do I really need XA connections even if I am using remote EJB invocations.

      I am sure I am missing some concept here . I tried to go through many websites but couldn’t find a convincing answer to myself.
        • 1. Re: XA Connection concept
          user10079576 wrote:
          . Why do we need XA connection ?
          That is a question for which the answer can fill an entire book. Research 'distributed transactions' to hopefully learn the why along the way - its going to be a long sitting to absorb all that information.