6 Replies Latest reply on Jan 24, 2004 5:21 AM by spetersodlb

    MDB Rollback & no transaction context

    spetersodlb

      I'm getting the oft-reported "setRollbackOnly must only be called in the context of a transaction" message when I call ctx.setRollbackOnly() from my onMessage() method.

      Yes, I have the following in my ejb-jar.xml:

      <container-transaction >
      <ejb-name>myMDB</ejb-name>
      <method-name>onMessage</method-name>
      <trans-attribute>Required</trans-attribute>
      </container-transaction>

      I also tried "RequiresNew" for the trans-attribute, same result. I also tried "*" for the method name parameter, same result.

      Other than this, my MDB works fine.

      JBoss version is 3.2.3
      I've read this entire forum, searched in the other forums for transaction-related problems, and read both the "getting started" book and the August 4, 2003 edition of the JBoss Administration and Development book, chapter on Transactions and chapter on JMS. I'm sure I'm missing something obvious. Give me a hint, please...

        • 1. Re: MDB Rollback & no transaction context

          You have assembly-descriptor?

          <ejb-jar>
          ....

          <assembly-descriptor>
          <container-transaction >
          <ejb-name>myMDB</ejb-name>
          <method-name>onMessage</method-name>
          <trans-attribute>Required</trans-attribute>
          </container-transaction>
          </assembly-descriptor>
          </ejb-jar>

          Regards,
          Adrian

          • 2. Re: MDB Rollback & no transaction context
            spetersodlb

            Yup, my other container transactions are in there as well.

            I should also probably add that I'm using the default server, in case that make some difference.

            • 3. Re: MDB Rollback & no transaction context
              spetersodlb

              After a lot of trial and error, I've discovered the answer: somewhere in all my original floundering I managed to lose the tags that must surround the <ejb-name> and <method-name> tags. So the following works:

              <container-transaction >

              <ejb-name>myMDB</ejb-name>
              <method-name>onMessage</method-name>

              <trans-attribute>Required</trans-attribute>
              </container-transaction>


              But wait, there's more!

              If I use "RequiresNew" it doesn't work (I'm no expert on transactions, but it seems like it should).

              Also, I am using xdoclet (1.2b3 and 1.2) to generate the assembly-descriptor entries and it generates

              <method-name>*</method-name>

              if I use the ejb.transaction tag at the class level. This doesn't work.

              If I use the ejb.transaction tag at the method level, it generates

              <method-name>onMessage</method-name>
              <method-parms>
              ... method parm tags....
              </method-parms>

              which also doesn't work. (Seems like I read somewhere that this is/was a known problem). There may be some way to get xdoclet to generate what _does_ work, but I couldn't figure it out; the only way I've found so far is to use the assembly-descriptor merge point with the hand-coded xml listed above.

              Sure hope this saves someone else some trouble....

              • 4. Re: MDB Rollback & no transaction context
                spetersodlb

                Arrgh! Somehow my previous post got messed up. Here's what works:

                <container-transaction >

                <ejb-name>myMDB</ejb-name>
                <method-name>onMessage</method-name>

                <trans-attribute>Required</trans-attribute>
                </container-transaction>

                • 5. Re: MDB Rollback & no transaction context
                  spetersodlb

                  Guys, what is with the editor for this forum???? It insists on leaving out the
                  ... tags that are in my previous two posts! Maybe this will work. In my previous posts for what does work, insert after the <container-transaction> tag
                  the following: "" and before the <trans-attribute> tag insert "".

                  I'm crossing my fingers that this makes it in....

                  • 6. Re: MDB Rollback & no transaction context
                    spetersodlb

                    OK, I give up on providing the literal stuff you need. Here it is in English. After the <container-transaction> tag insert a "method" tag and before the <trans-attribute> tag insert a "/method" tag.