2 Replies Latest reply on Sep 21, 2003 7:52 AM by peejay

    Problems with setRollbackOnly

    peejay Newbie

      Hi!

      I use JBoss 3.2.1 and an Oracle8 database.
      My application consisting of some CMP-EntityBeans and some SessionBeans.

      My problem is that when i call the setRollbackOnly method from the context of a session bean, in some session beans it works as expected and in other beans it doesn't work.

      e.g. in some session beans this method writes out:
      rollback = false;

      /**
      * @ejb.interface-method
      * @ejb.transaction type="Required"
      */
      public void doSomething(...) throws Exception {
      ...
      context.setRollbackOnly();
      logger.debug("rollback = "+context.getRollbackOnly());
      ...
      }

      Why? Any Idea?

      Thanks in advance.

      peejay

        • 1. Re: Problems with setRollbackOnly
          peejay Newbie

          Maybe i found the solution for this behavoir.

          The doSomething method (see above) was called from
          the doSomeOtherThings method within the same bean A.

          /**
          * @ejb.interface-method
          * @ejb.transaction type="NotSupported"
          */
          public void doSomeOtherThings(...) {
          ...
          doSomething(...);
          ...
          }

          Can this cause the behavior (described above) of setRollbackOnly()?

          I think so because when i call the doSomething method from another bean B the method writes out rollback = true and the rollback is executed.

          Can somebody explain that to me? Is it impossible to call a method with another transaction attribut which is within the same bean instance?

          When the rollback is performed a TransactionRolledbackLocalException is throw from the doSomething method of bean A and the remove method of bean A is called.

          I want to call the doSomething method serveral times.
          So do i have to catch the TransactionRolledbackLocalException in bean B then or is there another way?

          Bean B:

          **
          * @ejb.interface-method
          * @ejb.transaction type="NotSupported"
          */
          public void callDoSomething(...) {
          ...
          while (...)
          try {
          doSomething(...);
          } catch (TransactionRolledbackLocalException e) {
          do nothing...
          }
          ...
          }


          Thanks in advance again

          peejay

          • 2. Re: Problems with setRollbackOnly
            peejay Newbie

            I have another problem with setRollbackOnly.

            I want to perform a bank transfer. And if something goes wrong I want to send a message to a queue and i want to rollback the transaction.

            I have a SLSB TransferHandler and another SLSB Sender which sends a message to a queue.

            The processTransfer method of the TransferHandler:

            Version 1:

            /**
            * @ejb.interface-method
            * @ejb.transaction type="Required"
            */
            public void processTransfer(...) {
            try {
            ...doSomething...
            } catch (AFailureException e) {
            context.setRollbackOnly();
            ...
            lookup Sender
            ...
            senderLocal.sendMessageToQueue();
            }
            }

            The sendMessageToQueue method of the Sender:

            /**
            * @ejb.interface-method
            * @ejb.transaction type="NotSupported"
            */
            public void sendMessageToQueue(...) {
            ...
            sends a message to a queue
            ...
            }


            If i run my application and an exception occures within processTransfer method version 1 the sendMessageToQueue method of Sender isnt called and a TransactionRolledbackLocalException is thrown.
            Why is the sendMessageToQueue method not called?
            I thought that the transaction is rolled back at the end of the transaction what in my case is the end of the processTransfer method.

            Then I changed the processTransfer method

            Version 2:

            /**
            * @ejb.interface-method
            * @ejb.transaction type="Required"
            */
            public void processTransfer(...) {
            try {
            ...doSomething...
            } catch (AFailureException e) {
            ...
            lookup Sender
            ...
            senderLocal.sendMessageToQueue();
            context.setRollbackOnly();
            }
            }

            Now the sendMessageToQueue method is called. But the processTransfers() doesnt throw a TransactionRolledbackLocalException. Why not?
            Any ideas?

            Thanks

            peejay