3 Replies Latest reply on Sep 2, 2002 1:25 PM by Dain Sundstrom

    500 A CMR collection may only be used within the transction

    Åsmund Hjulstad Newbie

      What does this really mean?

      HTTP ERROR: 500 A CMR collection may only be used within the transction in which it was created

      I have several servlets and jsp pages all accessing local interfaces on my entity beans. The "ncontext" object is stored in the session.

      // Get the "sig" object. This method will lazily
      // create an entity bean, and keep a reference to the
      // local interface.
      Signatur sig = ncontext.getSignatur();
      // This method navigates a one-to-many CMR relation
      Collection bevegelser = sig.getBevegelsesPoster();

      After this, if I do
      bevegelser.isEmpty() or bevegelser.iterator() in the same jsp, I get the error message above.

      (the rest is my jsp and prior calls)

      Aren't I supposed to be able to do this? I thought part of the concept behind local interfaces was that one could navigate cmr's from jsp's / servlets.

      Any ideas as to what might be wrong?

      Åsmund Hjulstad

        • 1. Re: 500 A CMR collection may only be used within the transct
          Åsmund Hjulstad Newbie

          Sorry, should have read the spec more carefully.

          This solves the problem:

          UserTransaction trans = new InitialContext().lookup("java:comp/UserTransaction");

          // do stuff

          Being spoiled with CMT when writing beans dulls my brain.. :-)

          However, one problem still remains:
          I use a MVC pattern, with a JSP view, servlet controller, and EJB Local-objects as the model. After having made changes to the data in the controller (servlet), and redirecting to the jsp page, the changes are not visible yet. A reload (1/2 sec afterwards) gives me the desired data.

          What can be done to fix this?

          (And BTW, when experiencing the previous problem, the response was not consistent. Sometimes it could work; after some irrelevant code changes (outputting more html), it wouldn't. Could this indicate that there is a timing issue of some sort related to the transaction manager? I'm using CVS as of January 18th, just before Marc Fleury started committing the UnifiedDeployer.. )

          • 2. [Jboss3.0.2] A CMR collection may only be used within the tr
            Adrian Hallam Newbie

            I have an application that worked in JBoss 3.0.0 and I moved to 3.0.2 to try and fix an unrelated problem.

            Now my existing code is giving me the following error:
            java.lang.IllegalStateException: A CMR collection may only be used within the transction in which it was created

            I have two CMP Entity Beans (User and Roles). These are connected with a Many to Many relationship.

            My ejb-relationship looks like:







            In all the CMP examples I have looked at no one seems to play with the transactions directly - which seems to be what this thread is suggesting? I have both EJB's in <container-transaction> section and <trans-attribute> set to Required.

            The code snippet is:

            // OK
            UserLocalHome myUserHome = getUserLocalHome();
            UserLocal myUser = myUserHome.findByPrimaryKey(username);

            // OK
            RolesLocalHome myRoleHome = getRolesLocalHome();
            RolesLocal myRole = myRoleHome.findByName(roleName);

            // Exception thrown on this line
            if( myUser.getRoles().contains(myRole) ) {

            I have spent many hours searching forums, etc. but I wouldn't be suprised if I'm just doing something stupid...

            Any advice would be greatly appreciated.


            • 3. Re: [Jboss3.0.2] A CMR collection may only be used within th
              Dain Sundstrom Master

              The code needs to be wrapped in a transaction using either a UserTransaction or a SessionBean.