11 Replies Latest reply on Oct 9, 2002 1:09 PM by aloubyansky

    Sample for transaction

    dwong

      Hi there,

      Could anyone post sample files for showing how to make a transaction, say, the client (jsp) calls a session bean which calls several CMPs for oracle8i and jboss3.0.3 ? Any special configuration files needed ?


        • 1. Re: Sample for transaction
          aloubyansky

          You can use user transaction or implement a session facade (recommended).

          To get user transaction:
          {
          InitialContext ctx = new InitialContext();
          tx = (UserTransaction) ctx.lookup("UserTransaction");
          tx.begin();
          // do smth
          if(tx.getStatus() == Status.STATUS_ACTIVE) {
          tx.commit();
          }

          Consider Dain's book JBossCMP.

          • 2. Re: Sample for transaction
            dwong

            Thanks for your sample code. I've tried it out but failed.

            In my session bean:
            {
            InitialContext ctx = new InitialContext();
            tx = (UserTransaction) ctx.lookup("UserTransaction");
            tx.begin();
            // do smth
            // call a BMP to insert a record to table A
            // call another BMP to insert a record to table B
            if(tx.getStatus() == Status.STATUS_ACTIVE) {
            tx.commit();
            }

            The first record commit whatever the result of the second insert, i.e. if the second insert has ORA errors, the first insert still succeeds. I've added a sleep between 2 inserts and finds that after 1st insert, it is already committed. Any hints ?

            • 3. Re: Sample for transaction
              aloubyansky

              I would suggest you to ask this question in jboss-user mailing list.
              Do you use CMT and XA-configuration?

              • 4. Re: Sample for transaction
                dwong

                Hi, thanks again for your advice.

                Attached are the configuration files I used.

                Sorry, I don't know what's the difference between XA and CMT ? I think I have tried using the method of user transaction (the one you gave me) and the container-managed transaction.

                Also, could you where I can find the jboss mailing list ?

                Thanks again !

                • 5. Re: Sample for transaction
                  aloubyansky

                  I beleive you should use XA datasource configuration. You should be able to find examples for Oracle in docs directory.
                  Lists are here:
                  http://sourceforge.net/mail/?group_id=22866

                  • 6. Re: Sample for transaction
                    dwong

                    Do you mean using the oracle-xa-service.xml instead of oracle-service.xml ? In oracle-xa-service.xml, it mentions about transaction-service.xml ? Should I use it and do u have any example for transaction-service.xml ?

                    Thanks for your follow up !!!

                    • 7. Re: Sample for transaction
                      aloubyansky

                      Sure, if you have XA compliant datasource then why not use it?
                      Don't you see transaction-service.xml in the deploy dir?
                      BTW, it has hints for Oracle.

                      • 8. Re: Sample for transaction
                        dwong

                        Hi,

                        I cannot find transaction-service.xml. BTW, I moved away oracle-service.xml and put oracle-xa-service.xml in the deploy directory and change those XAOracleDS to OracleDS in the oracle-xa-service.xml (so that I do not need to change the lookup in my beans).

                        I can see that the connection pool has been set from the v$session. However, when the CMP bean is called, the exception occurs:
                        javax.ejb.FinderException: Find failed: java.lang.IllegalArgumentException: null xaRes

                        I am sorry that I don't know what's happen and the difference between oracle-service.xml and oracle-xa-service.xml. Any other modifications needed ?

                        Thanks

                        • 9. Re: Sample for transaction
                          aloubyansky

                          Do see the following in oracle-xa-service.xml:
                          <!-- ==================================================================== -->
                          <!-- ConnectionManager setup for xa oracle dbs -->
                          <!-- Thanks to igor fedorenko <ifedorenko@thinkdynamics.com> -->
                          <!-- Build jmx-api (build/build.sh all) and view for config documentation -->
                          <!-- YOU MUST CHANGE THE XidFactoryMBean config (in conf/jboss-service.xml -->
                          <!-- or transaction-service.xml) to this: -->
                          <!--

                          true

                          -->

                          Have you applied it? note: it can be done in conf/jboss-service.xml.

                          Don't be sorry that you don't know ;)

                          • 10. Re: Sample for transaction
                            dwong

                            Yes,I have applied to jboss-service.xml but not to transaction-service.xml (as I don't have this file).

                            Do u have any workable sample config and bean files for container-managed transaction ?

                            One more strange thing is that with oracle-service.xml, the no. of connection keeps increased but not shrinked, and eventually running out of connection to oracle. It seems that the connection is not reused but keep created for every call to CMP bean. Do u know why and how to solve it ?

                            I am not sure if these questions are dump or no one has experienced such problems as observed from the response for these questions in those forums.

                            Thanks.

                            • 11. Re: Sample for transaction
                              aloubyansky

                              I suggest you to ask these question in Datasource Configuration forum or jboss user mailing list. I beleive you'll get more feedback.