9 Replies Latest reply on May 1, 2003 8:05 AM by trugbild

    Transaction-Status

    trugbild

      Another transaction-problem:
      how can I get the Status of a currently running transaction (which is defined by the declarative way - not the programmatic).

      In other words (if my Englisch is too bad to make me understandable):
      I want to get the transaction-status from within a bean-method, which is controlled by programmatic transactions (defined in the ejb-jar.xml).

      How can I get the transaction-object?

        • 1. Re: Transaction-Status

          There are methods on the bean context
          to control the transaction.

          public boolean getRollbackOnly() ;
          public void setRollbackOnly();

          Regards,
          Adrian

          • 2. Re: Transaction-Status
            trugbild

            Thanks for your answer, but this is not exactly what I wanted to know...
            I do not want to CHANGE the status, only GET it.

            • 3. Re: Transaction-Status

              What is wrong with getRollbackOnly() ?

              You can use the TransactionManger bound at
              "java:/TransactionManager" to access the transaction.

              Regards,
              Adrian

              • 4. Re: Transaction-Status
                trugbild

                > What is wrong with getRollbackOnly() ?
                It only returns if the transaction is going to be rolled back or not.
                But there are several other status, like "active" or "prepared". But in the j2ee-API-Documentation I found, that the method "getUserTransaction()" is available for SessionContext-objects. So I try this one first...
                I think I would get the same object if I get the Transaction via TransactionManager, is this correct?

                • 5. Re: Transaction-Status

                  UserTranscations are for BMT (bean managed transactions).

                  The other statuses don't apply inside the bean
                  for CMT. You are either active or marked rollback.
                  The other statuses apply at the end of the work
                  when the container is committing/rolling back the
                  transaction.

                  Regards,
                  Adrian

                  • 6. Re: Transaction-Status
                    trugbild

                    So the getUserTransaction() only returns an object, if I invoked the bean from within a bean-managed transaction? And if I control the transaction with a servlet?
                    And with container-managed transaction getUserTransaction returns null?
                    hmm... perhaps I should try it...

                    • 7. Re: Transaction-Status
                      trugbild

                      By the way:
                      I wonder what happens to transactions if they get suspended (e.g. when a method in a transaction invokes another method which is set to RequiresNew)

                      • 8. Re: Transaction-Status

                        The getUserTransaction() method
                        creates a UT when one is not already assigned
                        to the bean.
                        For CMT it throws an exception.

                        For BMT any previous transaction is suspended.

                        If you invoke a RequiresNew method your
                        transaction is suspended, but it is activated again
                        by the time it returns to your method.
                        So the suspension is invisible to you.

                        Regards,
                        Adrian

                        • 9. Re: Transaction-Status
                          trugbild

                          I know that it isn't my business how a transaction gets suspended and how it is activated again. But I would really like to know (only the essence of it - no details, of course).

                          Remember my statement about the documentation?
                          Maybe you're glad to here, that I begun writing a tutorial about transactions, yesterday... (in German).
                          I'm reading and testing all the time. I'll put it on the web when it's finished...

                          Thanks for your help!