3 Replies Latest reply on Nov 22, 2002 8:52 AM by adrian.brock

    Exception when trying to call "create" in a entity bean

    mecva

      Hi all,

      I'm trying to migrate some entity beans from Sun J2EE to JBoss. I think I have succeeded deploying it on JBoss but when I try to call "create" in one specific entity bean it happens the following exception:

      10:59:36,929 ERROR [LogInterceptor] RuntimeException:
      java.lang.IllegalStateException: INSERTING AN ALREADY EXISTING BEAN, ID = 0
      at org.jboss.ejb.plugins.AbstractInstanceCache.insert(AbstractInstanceCache.java:222)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:103)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:79)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:44)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:111)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:105)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:129)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
      at org.jboss.ejb.Container.invoke(Container.java:730)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1058)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:382)
      at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      at java.lang.Thread.run(Thread.java:536)

      The exception does not occur in all calls of "create" that I do, but in some. However the calls are the same when the exception occurs and when not.
      Anybody knows what could be?

      Thanks in advance,

      Marcio Azevedo.

        • 1. Re: Exception when trying to call "create" in a entity bean

          Have you already created an entity with the same
          primary key? In this case 0
          Perhaps your ejbCreate should should be throwing
          a DuplicateKeyException?
          Maybe your primary key doesn't implement
          equals() correctly?

          Regards,
          Adrian

          • 2. Re: Exception when trying to call "create" in a entity bean
            mecva

            I haven't created an entity with the same primary key because the PK, in this case, is auto incrementable. But I usually pass 0 as the PK because it shall be ignored. And I do the same in others entity beans which I don't have the exception.
            Another information that I have found out is that when the exception occurs, the auto increment counter is incremented to the PK. I mean, if I invoke "create", and the exception doesn't occur, it is stored a row in the table that the PK value is "X". If, after that, I invoke "create" again and the exception occurs, nothing is stored in the table. When I invoke "create" once more and the exception doesn't occur, it is stored a row in the table that the PK value is "X+2". It means that the PK "X+1" was jumped.
            I hope it helps the problem's understanding.
            Thanks a lot.
            Marcio Azevedo.

            • 3. Re: Exception when trying to call "create" in a entity bean

              Which version of JBoss are you using?
              Only JBoss3.2 supports auto-increment.
              Check in the CMP forum for details.

              Regards,
              Adrian