1 Reply Latest reply on Apr 29, 2003 11:53 AM by Tim Paulson

    getting an errror when try to get cmr collection.Please Help

    Hemang Newbie

      Hi,
      I am getting the following exception when I try to use cmr collection from session bean

      12:09:33,157 ERROR [LogInterceptor] RuntimeException:
      java.lang.IllegalStateException: A CMR collection may only be used within the tr
      ansction in which it was created
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.getIdList(RelationS
      et.java:58)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.size(RelationSet.ja
      va:65)
      at java.util.ArrayList.(ArrayList.java:128)
      at com.eicjis.da.session.PartySessionBean.getRelatedReference(PartySessi
      onBean.java:613)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
      java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
      sorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
      tatelessSessionContainer.java:660)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invo
      ke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Stat
      elessSessionInstanceInterceptor.java:77)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:107)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:201)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:9
      2)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)

        • 1. Re: getting an errror when try to get cmr collection.Please
          Tim Paulson Newbie

          I have discovered a satisfactory answer to the problem of CMR-based transaction errors in JSPs/Servlets.
          I embedded a little bit of Java code into my JSP page to surround the CMR-based accesses with a transaction. I found out how to implement a transaction from a JBoss client in the QuickStart guide. Here is the relevant part of my JSP page:

          <%@ page import="javax.naming.*,javax.transaction.UserTransaction" %>


          IdDescriptionCost
          <%
          Context jndiContext = new InitialContext();
          UserTransaction ut = (UserTransaction)jndiContext.lookup("UserTransaction");
          ut.begin();
          %>
          <c:forEach var="buy" items="${indiv.buys}">

          <c:out value="${buy.buyId}"/>
          <c:out value="${buy.description}"/>
          <c:out value="${buy.cost}"/>

          </c:forEach>
          <%
          ut.commit();
          %>


          In this case, I am using JSTL tags to control the loop and to access each of the "Buy" EJBs that are returned by the JSTL-based expression "${indiv.buys}". This expression is mapped to a EJB CMR accessor call (indiv.getBuys()).

          So, at the moment I have some messy looking Java code that surrounds the CMR-based stuff with a transaction. But, this can easily be converted into a special tag in my own tag library. I plan to implement a tag like:

          <mine:user_transaction>
          <!-- CMR accesses -->
          </mine:user_transaction>

          Information about Transactions in JBoss can be found in the QuickStart guide.

          I think it would be good to add some CMR-based accesses to CrimePortalTest.java of the "JBoss 3.0 Template" code (http://prdownloads.sourceforge.net/jboss/JBoss.3.0TemplateAndExamples.zip).