5 Replies Latest reply on Sep 11, 2002 2:35 PM by dsundstrom

    Read only ejbs exception

    bombel

      Hi.

      I'm trying to play a liitle bit with read only entities based on CMP2.0 engine and it seems to me that setting read only flag for whole entity in jbosscmp-jdbc.xml

      I have marked tjem as read only in jbosscmp-jdbc.xml,
      set commit D option in jboss,xml for CMP2.0 container,
      "Supports" transaction attribute for session ejb(fascade) and "Supports" for entities which
      ensures that this ejbs will be invoked in non-transactional state.

      During second hit to this entity I'm getting following exception:

      java.lang.IllegalStateException: The iterator of a CMR collection may only be used within the transction in which it was created
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.verifyIteratorIsValid(RelationSet.java:309)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.hasNext(RelationSet.java:269)
      at com.dsrg.ejb.laboratorycmp2_0.LaboratorySLBean.calculateGroupScoreEstimation(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:660)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77)


      .......

      any ideas?

        • 1. Re: Read only ejbs exception
          attachvishal

          Have u returned the collection of CMR field (means collection of local interfaces) outside the bean where u have defined this relationship
          I hade the same problem where i called the abstract CMR method inside the session bean and tried to manupulate the collection of the local interfaces returned by the CMR abstract method

          • 2. Re: Read only ejbs exception
            bombel

            Yes. I'm iterating over the relation inside session ejb,
            and next from each result I'm acquiring value objects
            and if it's needed also any other related ejbs.

            Anyway if this a problem cause, I think that this behaviour is incorrect. ?????

            • 3. Re: Read only ejbs exception
              dsundstrom

              The problem is you are having is caused by getting an iterator in one transaction (or no transaction) and using it in another. This behavior and exception are required by the EJB 2.0 specification.

              • 4. Re: Read only ejbs exception
                bombel

                I found the very simple solution for this.
                When I want to get all CMR related ejbs
                I'm not using a collection but simple array:

                Object[] tasks_array = testEJBLocal.getTasks().toArray();

                next I'm iterating over this array insted of collection and everything is working fine.

                • 5. Re: Read only ejbs exception
                  dsundstrom

                  This is a common solution. I usually create a new ArrayList with the relationship collection to get a snapshot. Something like this:

                  ArrayList snapshot = new ArrayList(testEJBLocal.getTasks());