2 Replies Latest reply on Aug 16, 2002 11:43 AM by Gustavo Hexsel

    javax.jms.JMSException: Invalid transaction id

    ken Newbie

      Hello ,

      I am attempting to publish a message from my session bean to a client. However the following exception is thrown :

      javax.jms.JMSException: Invalid transaction id.
      at org.jboss.mq.SpyXAResourceManager.addMessage(SpyXAResourceManager.java:76)

      at org.jboss.mq.SpySession.sendMessage(SpySession.java:396)


      Here is the contents of my ejb-jar.xml file :

      <ejb-jar>

      <enterprise-beans>

      <display-name>FirstEJB</display-name>
      <ejb-name>First</ejb-name>
      com.stardeveloper.ejb.session.FirstHome
      com.stardeveloper.ejb.session.First
      <ejb-class>com.stardeveloper.ejb.session.FirstEJB</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
      <resource-ref>
      A Topic ConnectionFactory
      <res-ref-name>jms/MyTopicConnection</res-ref-name>
      <res-type>javax.jms.TopicConnectionFactory</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
      <resource-ref>
      A Topic
      <res-ref-name>jms/TopicName</res-ref-name>
      <res-type>javax.jms.Topic</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      </enterprise-beans>

      <assembly-descriptor>
      <container-transaction>

      <ejb-name>First</ejb-name>
      <method-name>*</method-name>

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

      <security-role>
      Users
      <role-name>users</role-name>
      </security-role>
      </assembly-descriptor>
      </ejb-jar>


      The contents of jboss.xml are :



      false
      <resource-managers>
      <resource-manager>
      <res-name>topicfactoryref</res-name>
      <res-jndi-name>java:/JmsXA</res-jndi-name>
      </resource-manager>
      <resource-manager>
      <res-name>topicref</res-name>
      <res-jndi-name>topic/testTopic</res-jndi-name>
      </resource-manager>
      </resource-managers>

      <enterprise-beans>

      <ejb-name>First</ejb-name>
      <jndi-name>ejb/First</jndi-name>
      <configuration-name>Standard Stateless SessionBean</configuration-name>
      <resource-ref>
      <res-ref-name>jms/MyTopicConnection</res-ref-name>
      <resource-name>topicfactoryref</resource-name>
      </resource-ref>
      <resource-ref>
      <res-ref-name>jms/TopicName</res-ref-name>
      <resource-name>topicref</resource-name>
      </resource-ref>


      </enterprise-beans>



      An finally here is the bean code for sending a message :

      private static final String CONNECTION_JNDI =
      "java:comp/env/jms/MyTopicConnection";

      private static final String TOPIC_JNDI = "java:comp/env/jms/TopicName";

      // Lookup the topic
      topic = (Topic)context.lookup(TOPIC_JNDI);

      // Lookup the connection factory
      TopicConnectionFactory factory =
      (TopicConnectionFactory)context.lookup(CONNECTION_JNDI);

      topicConnection = factory.createTopicConnection();

      TopicPublisher topicPublisher = null;
      TextMessage message = null;

      // Create a session
      topicSession = topicConnection.createTopicSession(true,
      Session.AUTO_ACKNOWLEDGE);

      // Create a publisher
      topicPublisher = topicSession.createPublisher(topic);

      // Create a message
      message = topicSession.createTextMessage();
      message.setText(msg);

      // Publish it
      System.out.println("Publishing message " + msg);
      topicPublisher.publish(message);

      } catch (JMSException ex) {


      In the jboss.jcml file I placed the following line:




      I would really appreciate any help,

      Thank,

      Ken.

        • 1. Re: javax.jms.JMSException: Invalid transaction id
          Thomas Laresch Newbie

          I searched the Messaging, JMS & JBossMQ forum for "invalid transaction id" and got exactly 50 results. Apparently this is a common problem,
          and none of these results were helpful.

          Hopefully this message will help.

          (I find it very annoying that people post messages like "I got the problem. I was defining the ejb.xml file wrong." At least try to share some information!)

          I had this problem for the last day and only solved it by painstakingly examining the JBoss Workbook Chapter 13.2 example. This example runs with no problem. However, if you try to make your own Message Driven Bean, it is easy to miss an important part of the ejb-jar.xml:
          <assembly-descriptor>
          <security-role>
          <role-name>everyone</role-name>
          </security-role>

          <container-transaction>

          <ejb-name>ReservationProcessorEJB</ejb-name>
          <method-name>*</method-name>


          <trans-attribute>Required</trans-attribute>
          </container-transaction>
          </assembly-descriptor>
          This needs to be outside of your enterprise-beans tag.

          If you are having this problem, try adding this XML (with your own EJB name, of course) to ejb-jar.xml.

          If you still have a problem, I highly recommend that you run through the JBoss Workbook Chapter 13 to prove to yourself that JMS/Message Driven Beans do work in JBoss. Then move forward from there.

          Workbook is at http://www.titan-books.net/download.html. I consider the workbook the best way to get all the JBoss concepts up and running quickly.

          Ken, in your case, I suspect the problem may be that your trans-attribute is set to Supports. I would try Required. I realize you are using Session beans, so I may be off, but try it and let us know. Good luck.

          - Tom

          • 2. Re: javax.jms.JMSException: Invalid transaction id
            Gustavo Hexsel Newbie

            I had a similar problem, I was using an MDB as a dispatcher to other MDBs. But I always got into that dreaded invalid transaction ID. I guess that the problem was that I was mixing local transactions with JmsXA. When I started to get the Jms connections through ConnectionFactory it stopped complaining.