2 Replies Latest reply on Mar 22, 2003 5:43 AM by frankielam

    CMR IllegalStateException

      We are using JBoss 3.0.0 & are getting an intermitent exception as follows:

      17:51:32,531 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
      java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.getIdList(RelationSet.java:58)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.toArray(RelationSet.java:232)
      at utilities.ContentHandler.getSourceFiles(ContentHandler.java:358)
      at org.apache.jsp.createPlaylist$jsp._jspService(createPlaylist$jsp.java:823)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)

      The exception is thrown from a jsp page in which we are looping through an ejb called Content. Content has a many to many relation with an ejb called Source. During the loop through Content, we also access Source & display items from both Content & Source.
      Any idea what could be causing the exception? Any idea what we can do to fix it?

      Thanks,
      Josephine

        • 1. Re: CMR IllegalStateException

          We figured out the solution. I thought I would post the answer in case anyone else comes across this problem....
          Need to use Transactions....(This will also increase performance quite nicely.)
          Put this code snipet around any calls to EJBs....

          import javax.naming.InitialContext;
          import javax.transaction.*;

          UserTransaction tx = null;
          try
          {
          // Start Transaction
          InitialContext ctx = new InitialContext();
          tx = (UserTransaction)ctx.lookup("UserTransaction");
          tx.begin();

          //EJB code calls, etc, go here...

          if( tx.getStatus()==Status.STATUS_ACTIVE)
          {
          tx.commit();
          }

          }
          catch(Exception e)
          {
          try
          {
          if( tx !=null)
          tx.rollback();
          }
          catch(SystemException unused)
          {
          //do whatever
          }
          }

          • 2. Re: CMR IllegalStateException
            frankielam

            A real lifesaver. Thanks!