2 Replies Latest reply on Nov 25, 2002 6:57 AM by Zarni Worgl

    java.lang.IllegalStateException: A CMR collection may only b

    Zarni Worgl Newbie

      Help wanted!
      I have a collection of beans that has a cmr field. If i try to iterate over the cmr field i get this error, but only in JBoss 3.0.4...

      original exception as thrown by jboss
      >java.lang.IllegalStateException: A CMR collection may only >be used within the transction in which it was created


      If I use JBoss3.0.0 this exception is not thrown.

      here's an example of what I'm doing...

      let's say Item is the bean i'm iterating over and while iterating I call a CMR get method:

      ArrayList relatedBeans = new ArrayList( Item.getCMRbeans );

      this work's fine but when I try to iterate over this new collection and do some get methods on it I get that ugly exception.

      Maybe it's just JBoss 3.0.4 making the problem...
      Maybe it's some transaction problem, my beans are all transaction Requiered...
      Maybe it's JBoss....
      Maybe it's me...

      I don't know...
      Someone please help.

      zarni

        • 1. Re: java.lang.IllegalStateException: A CMR collection may on
          nqin Newbie

          I have a similar problem. I have entity bean "class" and entity bean "section" with one-to-many relationship. Both entity beans have only local interface. And have a session bean. When my session bean call class.getSection(). It throws a exception- CMR can only be accessed inside the transaction which CMR is created.
          Here is something thread discussed about this issue before. But I still think solution is not reasonable. I specify my session bean with "required" container-managed transaction and both entity beans with "required" container-managed transaction, which suggests that my entity bean method will be included inside the transaction of session bean method which called entity bean method. However this is not the case and I still got the exception.
          So I modified my session bean method to following:

          InitialContext lcontext=new InitialContext();
          UserTransaction transaction=(UserTransaction)lcontext.lookup("UserTransaction"); transaction.begin();
          try{
          col.addAll(theClass.getSection());
          } catch(Exception e)
          { }

          And this time it works. So it seems even I specify "required" for my session bean. But there is no transaction initialied when I use my session bean.
          Wouldn't this be wrong?

          • 2. Re: java.lang.IllegalStateException: A CMR collection may on
            Zarni Worgl Newbie

            This transactions are all kind of weird!

            I used UserTransaction in my jsp page and it worked fine!
            But when I tried to wrap the logic in a tag like:
            <init:transaction>
            code...
            </init:transaction>
            It just won't go...