1 2 Previous Next 19 Replies Latest reply on Nov 20, 2006 10:38 AM by weston.price Go to original post
      • 15. Re: XA Connection error

        Thanks again,

        The reason that I went with XA in the first place is just to leave myself the option of hitting multiple databases in the future. I am working on a "proof of concept" type application that is only hitting an Oracle database right now but could hit another DB2 database in the future as well as Oracle. I guess it is easy enough to switch back to XA if it becomes necessary since everything (mostly) is declaritive.

        So if I go with local-Tx all the UserTransaction logic still applies the same as it would with XA, correct?

        I really appreciate all the help you have given me and all the patience. Thanks again.

        -Brian

        • 16. Re: XA Connection error
          weston.price

          Right, easy enough to switch out XA/Local when necessary.


          So if I go with local-Tx all the UserTransaction logic still applies the same as it would with XA, correct?


          Absolutely. There is no difference between the two in this regard. The code remains the same. Again, all you are doing is demarcating the transaction. One thing you may want to consider is leveraging the Servlet/JSP lifecycle stuff to make the transaction logic cleaner. Rather than litering your code with ut.begin(), ut.commit(), ut.rollback() stuff, you should be able to isolate this in one place and apply it where necessary.

          • 17. Re: XA Connection error
            weston.price

            Note, on the deployment stuff:

            There is nothing to prevent you from deploying both a <local-tx-datasource> and <xa-datasource> at the same time in JBoss. Since you are looking things up via JNDI you can always change the JNDI name depending upon your needs so you wouldn't have to rework anything beyond changing the JNDI in the code when the time came to use XA.

            Even better, use a resource-ref to introduce a logical binding between the WAR file and the underling JNDI resource. Check the Servlet/JSP spec for how to do this in JBoss. This would be the best bet as you would only have to change the web.xml/jboss-web.xml files when the time came to make the switch.



            • 18. Re: XA Connection error
              bocio

               

              "weston.price@jboss.com" wrote:
              Let me see if I can explain this a bit more clearly:

              In your case, it does not appear that you are leveraging CMT or using the UserTransaction object from JNDI to start/commit a transaction. If that is indeed the case, you are going to want to use the

              <no-tx-datasource>

              Using this requires you to do the setAutoCommit(false) and commit explicitly, otherwise, ever statement issued will be done in the context of a seperate JDBC transaction. In that scenario your *code* was correct, but the type of datasource was wrong.

              If you wanted to get away from managing your own transactions and leverage J2EE transaction management there are generally two approaches:

              1) Use EJB (or some other declaractive transaction technology)

              2) Use the UserTransaction object from JNDI to start/commit/rollback a transaction.

              Typically #2 is used with straight Web (non-EJB) applications and looks something like this:

              Servlet or JSP

              Context ic = new InitialContext();
              UserTransaction ut =
               (UserTransaction) ic.lookup("java:comp/UserTransaction");
              ut.begin();
              // access resources transactionally here
              ut.commit();
              
              


              What we are talking about is transaction 'boundaries'. Technologies like EJB(2/3) allow you to declare transactions on method boundaries. Servlets/JSP do not, but allow access to the UserTransaction object (as can be seen above).

              Note, either approach is neither 'right' or 'wrong', it's simply a matter of what your application requires. However, since you are running in a J2EE environment, CMT or UserTransaction delinated boundaries are typcially the preferred approach.




              One of the best post on the topic.
              Why don't you add this post on the wiki?



              • 19. Re: XA Connection error
                weston.price

                On my TODO list. Lots of info on the Wiki needs to be updated. Thanks for reminding me.

                1 2 Previous Next