2 Replies Latest reply on Mar 10, 2003 7:02 AM by Sean Ryan

    java.lang.IllegalStateException: The iterator of a CMR colle

    Sean Ryan Newbie

      Hi all.

      We have been experiencing the error below intermittently during testing of our application using JMeter. The error happens between one and five times over the course of 800 samples (with 10 threads) - only when using commit option A. It works fine for option B, but this is approx 5 times slower.

      13:40:15,000 ERROR [STDERR] java.lang.IllegalStateException: The iterator of a CMR collection may only be used within the transction in which it was created
      13:40:15,062 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.verifyIteratorIsValid(RelationSet.java:309)
      13:40:15,062 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet$1.hasNext(RelationSet.java:269)
      13:40:15,078 ERROR [STDERR] at net.lm.lis.services.main.RetrieveLearnerMasterViewCommand.execute(RetrieveLearnerMasterViewCommand.java:63)
      13:40:15,078 ERROR [STDERR] at net.lm.patterns.command.EJBAbstractCommand.execute(EJBAbstractCommand.java:23)
      13:40:15,078 ERROR [STDERR] at net.lm.lis.services.main.LisMainServiceEJB.executeCommand(LisMainServiceEJB.java:26)
      13:40:15,109 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source)
      13:40:15,109 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      13:40:15,125 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:324)
      13:40:15,125 ERROR [STDERR] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:660)

      The piece of code that fails is:

      Iterator l_securityRoles = l_securityLocal.getSecurityRoles().iterator();
      while (l_securityRoles.hasNext())
      SecurityRoleLocal l_securityRoleLocal = (SecurityRoleLocal)l_securityRoles.next();
      SecurityRoleValue l_securityRoleValue = l_valueObjectFactory.createSecurityRole(l_securityRoleLocal);

      The line on which the failure occurs is while(l_securityRoles.hasNext()). I have done some playing with this, and it seems that the failure always occurs on the second iteration of this loop (ie the second time hasNext() is evaluated). The securityRoles collection for the purposes of our test only ever contains one item.

      After trying various things to fix this, I came up with this code which doesn't fail at all.

      SecurityRoleLocal[] l_securityRoles = (SecurityRoleLocal[])l_securityLocal.getSecurityRoles().toArray(new SecurityRoleLocal[]{});
      for (int i=0; i<l_securityRoles.length; i++)
      SecurityRoleLocal l_securityRoleLocal = l_securityRoles;
      SecurityRoleValue l_securityRoleValue = l_valueObjectFactory.createSecurityRole(l_securityRoleLocal);

      It seems to me that the problem is not with my original code, as I don't do anything in my code that would constitute the end of a transaction. I've had a look with the RelationSet source code, but it hasn't shed any light on the matter for me.

      So I wonder if anyone else has seen anything like this? And how/if they've resolved it. We have a lot of 1:M and M:M CMR relations, hence quite a lot of this type of iteraton.

      Any help would be greatly appreciated.

      thanks in advance
      Sean Ryan