3 Replies Latest reply on Dec 23, 2012 3:29 PM by atijms

    Two-phase commit using an XA-datasource

    jecmenb

      Howdy!

      I'd like to ask a question about using an xa-datasource defined within my AS7 instance.

      What I did: I defined two different xa-datasources pointing to two databases

      What I need: I need to implement a two phase commit using those two xa-datasources mentioned above.

       

      Is there any Java sample/example how to use the JBoss transactional mechanism to do what I need?

      As I understood, I can (I have to) use an ordinary DataSource instead of XADataSource in my code, right? How does it work? What is the right way to do following:

      1. Create two connections to 2 different DBs (using xa-datasources defined within my AS7)

      2. Do some operations over both of them

      3. Do a final commit (or rollback if any error)

       

      Last question - what's the role of the JBoss's TransactionManager? How does it work? Is it hidden for the developers or do we need to instantiate it explicitly?

       

      Since I didn't found any sufficient answer I appreciate any explanation and help!

       

      Thanks a lot,

      Bobo

        • 1. Re: Two-phase commit using an XA-datasource
          mmusgrov

          The AS7 quickstarts (https://github.com/jboss-jdf/jboss-as-quickstart) have some transactions examples including how to update two datasources within a single transaction (look for CMT, BMT, jts and the crash-rec examples).

           

          It is possible to enlist a single non-XA aware datasource (search for LRCO for details) but we don't support it since it is not a recommended configuration.

           

          The transaction manager is initialised by the AS so you don't create it yourself. Normally you would use the EJB mechanisms for controlling transactions - the quickstarts cover both bean managed and container managed transactions. If you really want to get hold of the transaction manager you can look it up via JNDI (but the name is not standardised by the specifications, I believe AS7 uses java:jboss/TransactionManager).

          1 of 1 people found this helpful
          • 2. Re: Two-phase commit using an XA-datasource
            jecmenb

            Hey, Michael

            Great, thanks for the very quick reply.

             

            So the right way is to implement a SessionBean encapsulating let say both of my SQL inserts (for instance), right?

            Thanks again for your answer.

             

            Cheers,

            Bobo

            • 3. Re: Two-phase commit using an XA-datasource
              atijms

              If you really want to get hold of the transaction manager you can look it up via JNDI (but the name is not standardised by the specifications, I believe AS7 uses java:jboss/TransactionManager).

               

              It indeed isn't standardized. I've created a spec issue some time ago to standardize this. If you, or anyone else thinks this is important too, please vote for it at: http://java.net/jira/browse/JAVAEE_SPEC-8

               

              The issue with those names being not standardized is not even so much that they differ between application servers of different vendors, but that they differ between versions of the same AS (e.g. JBoss AS 6 vs JBoss AS 7).