4 Replies Latest reply on Dec 12, 2002 8:34 PM by magu

    IllegalStateException

    magu

      Hi,
      I have 2 CMP entity beans(street and block) and a one to many relation from the street to block. I have a session bean that makes the calls to create those entity beans.
      In one method of the session bean I do the following :

      Integer one = new Integer(1);
      try {
      Collection streets = streetHome.findAll_onloa();

      for (Iterator it = streets.iterator();it.hasNext(); ) {
      Street st = (Street)it.next();
      System.out.print(st.getName() + " ");

      Collection blocks = st.getBlocks();
      for (Iterator i = blocks.iterator(); i.hasNext(); ) {
      Block blk = (Block)i.next();
      System.out.print(blk.getLoHseNum() + " " + blk.getHiHseNum());
      }
      }
      }
      catch(Exception ex) {
      throw new FinderException("Error retrieving street/blocks information");
      }
      }
      }

      This code works fine for a while and then on the JBoss server I get the following:

      14:08:43,083 ERROR [LogInterceptor] TransactionRolledbackLocalException, causedB
      y:
      java.lang.IllegalStateException: removing bean lock and it has tx set!StreetEJB
      1384
      at org.jboss.ejb.plugins.lock.QueuedPessimisticEJBLock.removeRef(QueuedP
      essimisticEJBLock.java:412)
      at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:103)

      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockIntercep
      tor.java:124)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreation
      Interceptor.java:69)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
      rceptor.java:107)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
      torCMT.java:178)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
      0)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLoca
      lContainerInvoker.java:301)
      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
      at $Proxy48.getName(Unknown Source)
      at adddbmerge.SessionStreetBean.createMergeSession(SessionStreetBean.jav
      a:70)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      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:255)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
      0)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
      java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
      at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContai
      ner.java:313)
      at org.jboss.ejb.Container.invoke(Container.java:712)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:
      381)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
      at sun.rmi.transport.Transport$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Unknown Source)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour
      ce)
      at java.lang.Thread.run(Unknown Source)

      Because the corresponding tables in database are already created and I don't want to recreate it, because I need to keep the data, and the one to many relation is implemented already by storing the street id in the block table I use this field to indicate the relation in my descriptor as follows:


      <display-name>Street</display-name>
      <ejb-name>StreetEJB</ejb-name>
      <local-home>adddbmerge.StreetHome</local-home>
      adddbmerge.Street
      <ejb-class>adddbmerge.StreetBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>adb_street_r</abstract-schema-name>

      <cmp-field><field-name>streetId</field-name></cmp-field>
      <cmp-field><field-name>name</field-name></cmp-field>
      <cmp-field><field-name>defStreetId</field-name></cmp-field>
      <cmp-field><field-name>dist</field-name></cmp-field>
      <cmp-field><field-name>svcFlg</field-name></cmp-field>
      <primkey-field>streetId</primkey-field>

      <display-name>Block</display-name>
      <ejb-name>BlockEJB</ejb-name>
      <local-home>adddbmerge.BlockHome</local-home>
      adddbmerge.Block
      <ejb-class>adddbmerge.BlockBean</ejb-class>

      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Integer</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>adb_blockface_r</abstract-schema-name>

      <cmp-field><field-name>blockId</field-name></cmp-field>
      <cmp-field><field-name>evnOdd</field-name></cmp-field>
      <cmp-field><field-name>loHseNum</field-name></cmp-field>
      <cmp-field><field-name>hiHseNum</field-name></cmp-field>
      <cmp-field><field-name>mapRef</field-name></cmp-field>
      <cmp-field><field-name>streetId</field-name></cmp-field>
      <cmp-field><field-name>transZn</field-name></cmp-field>
      <cmp-field><field-name>loLat</field-name></cmp-field>
      <cmp-field><field-name>loLon</field-name></cmp-field>
      <cmp-field><field-name>hiLat</field-name></cmp-field>
      <cmp-field><field-name>hiLon</field-name></cmp-field>
      <cmp-field><field-name>zip</field-name></cmp-field>
      <primkey-field>blockId</primkey-field>

      <ejb-relation>
      <ejb-relation-name>Street-Block</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>street-has-blocks</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>StreetEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>blocks</cmr-field-name>
      <cmr-field-type>java.util.Set</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>block-belongs-to-street</ejb-relationship-role-name>
      Many
      <cascade-delete/>
      <relationship-role-source>
      <ejb-name>BlockEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>streetId</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>


      <assembly-descriptor>
      <container-transaction>

      <ejb-name>StreetEJB</ejb-name>
      <method-name>*</method-name>


      <ejb-name>BlockEJB</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>

      <container-transaction>

      <ejb-name>SessionStreetEJB</ejb-name>
      <method-name>createMergeSession</method-name>

      <trans-attribute>RequiresNew</trans-attribute>
      </container-transaction>
      </assembly-descriptor>

      If this will cause the exception I am getting how can I fix it without recreating the tables ? I red the other posts and I have seen references to custom primary key and hash functions. Is this the case that I have a custom primary key ? Where are the hash functions defined ?

      Many thanks

        • 1. Re: IllegalStateException
          magu

          One more thing JBoss version 3.0.3.

          • 2. Re: IllegalStateException
            magu

            On a subsequent run of the same code posted in my first post I get:
            17:31:25,582 ERROR [LogInterceptor] TransactionRolledbackLocalException, causedB
            y:
            javax.ejb.EJBException: Unexpected Error
            java.lang.OutOfMemoryError

            at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInte
            rceptor.java:205)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxIntercep
            torCMT.java:178)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
            0)
            at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
            java:130)
            at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
            at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
            at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLoca
            lContainerInvoker.java:301)
            at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)
            at $Proxy48.getBlocks(Unknown Source)
            at adddbmerge.SessionStreetBean.createMergeSession(SessionStreetBean.jav
            a:72)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            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:255)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:6
            0)
            at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.
            java:130)
            at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:203)
            at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContai
            ner.java:313)
            at org.jboss.ejb.Container.invoke(Container.java:712)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
            at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:
            381)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
            at sun.rmi.transport.Transport$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at sun.rmi.transport.Transport.serviceCall(Unknown Source)
            at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
            at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Sour
            ce)
            at java.lang.Thread.run(Unknown Source)

            almost in the same place ? right after the street that was causing the first posted exception. I certainly did not run out of memory as I was watching it and I had almost 50% free memory available. Before I decided to post this I got this OutOfMemory exception one more time but I was close to 100% memory usage ?!

            Several other times I got the exception IllegalStateException but in different places. As I mentioned in my first post the client works fine for a while reading from those 2 related tables.

            Please help. has anybody experience he same behavior ? I am running out of memory ? How can I tell ?

            Thanks

            • 3. Re: IllegalStateException
              olevy

              I have almost exactly the same problem! I also have a remote session bean talking to various local session entity beans, and my session bean iterates over the cmr relations.

              I've been looking through the forums looking for help on this issue and I have not seen anything useful other than there have been similar bugs in earlier versions. At any rate I do think this is probably a JBoss bug.

              I've tried my app on both 3.0.1 and 3.0.4 and gotten pretty much the same behaviour.

              I'm not yet clear on how to reproduce this reliably. On 3.0.1 I notice that my beans are getting passivated after a while and *then* when I try to access them again I get this error, so it seems like that this is a problem with passivation and activation.

              If you figure out a work around, please post it!

              • 4. Re: IllegalStateException
                magu

                Hi,
                Last time when I ran my app I got the following:
                On the server:
                16:52:40,331 WARN [TxCapsule] Transaction XidImpl [FormatId=257, GlobalId=DDS47//5, BranchQual=] timed out. status=STATUS_ACTIVE

                On the client:
                javax.ejb.FinderException: A CMR collection may only be used within the transction in which it was created
                at adddbmerge.SessionStreetBean.createMergeSession(SessionStreetBean.java:83)
                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                atError trying to create a sessionStreet bean A CMR collection may only be used within the transction in which it was created
                sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

                I have no clue how to solve this. If you think that this is a bug we need to submit a bug. I can not continue developing my app until I solve this issue. what do you think will be the best approach ?

                Cheers