7 Replies Latest reply on Sep 27, 2002 5:16 AM by fir99

    INSERTING AN ALREADY EXISTING BEAN

    lviggiano

      Hello,

      I am using JBoss 2.2.2 and with a BMP entity bean, we get the following exception. We created a set of bean calling the create(), then we remove some of them, and we re-insert them, and the exception happens randomly. I cannot figure out why. Can anyone help? The bean is generated by the JBuilder 6 EntityBean modeller whizard (with the dual persistence pattern).

      I believe that during the remove(), the object is not removed by the bean cache, so when we insert a bean with the same key after, it gives this error. Am I correct?

      Pressing the back button, and re-submitting the insert, it works...

      Does anyone knows something about this ?

      [TTelefonoMail] java.lang.IllegalStateException: INSERTING AN ALREADY EXISTING BEAN, ID = it.csi.sert.anagrafe.recapiti.TTelefonoMailPK@6095
      f2ba
      [TTelefonoMail] at org.jboss.ejb.plugins.AbstractInstanceCache.insert(AbstractInstanceCache.java:207)
      [TTelefonoMail] at org.jboss.ejb.plugins.BMPPersistenceManager.createEntity(BMPPersistenceManager.java:165)
      [TTelefonoMail] at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:441)
      [TTelefonoMail] at java.lang.reflect.Method.invoke(Native Method)
      [TTelefonoMail] at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:639)
      [TTelefonoMail] at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:160)
      [TTelefonoMail] at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:87)
      [TTelefonoMail] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:135)
      [TTelefonoMail] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:263)
      [TTelefonoMail] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
      [TTelefonoMail] at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:164)
      [TTelefonoMail] at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:106)
      [TTelefonoMail] at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:316)
      [TTelefonoMail] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invokeHome(JRMPContainerInvoker.java:436)
      [TTelefonoMail] at org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:212)
      [TTelefonoMail] at $Proxy54.create(Unknown Source)
      [TTelefonoMail] at it.csi.sert.anagrafe.SportelloBean.createTelefonoMail(SportelloBean.java:459)
      [TTelefonoMail] at java.lang.reflect.Method.invoke(Native Method)
      [TTelefonoMail] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:472)
      [TTelefonoMail] at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:87)
      [TTelefonoMail] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
      [TTelefonoMail] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:263)
      [TTelefonoMail] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
      [TTelefonoMail] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:190)
      [TTelefonoMail] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
      [TTelefonoMail] at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessionContainer.java:271)
      [TTelefonoMail] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerInvoker.java:392)
      [TTelefonoMail] at java.lang.reflect.Method.invoke(Native Method)
      [TTelefonoMail] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:241)
      [TTelefonoMail] at sun.rmi.transport.Transport$1.run(Transport.java:142)
      [TTelefonoMail] at java.security.AccessController.doPrivileged(Native Method)
      [TTelefonoMail] at sun.rmi.transport.Transport.serviceCall(Transport.java:139)
      [TTelefonoMail] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:443)
      [TTelefonoMail] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:643)
      [TTelefonoMail] at java.lang.Thread.run(Thread.java:484)
      [SertDS] Pool SertDS [0/5/100] returned object org.opentools.minerva.jdbc.xa.wrapper.XAConnectionImpl@52fc36 to the pool.

        • 1. Re: INSERTING AN ALREADY EXISTING BEAN
          daniela

          Hello Iviggiano,

          I have read your article. You have the same problem like I. The problem is the jboss container cache. If you delete an re-insert a data record in the same method into the session bean at the same function call, you must get this exception. The solution is you call from client two times the session bean. First you delete the data record and second you re-insert it.

          The problem is the following. You delete a record and you will insert a new data record with the same primary key like before. Into the database the data record does not exists. That is right. But jboss still have a reference in his application server cache. And that is the problem. I have test some different solution commencements. The only one solution are two calls from the client. If you call two method calls, jboss is cleared his cache after every call.

          Daniel

          • 2. Re: INSERTING AN ALREADY EXISTING BEAN
            lviggiano

            Hi Daniel,

            > The solution is you call from client two times
            > the session bean.

            What do you mean?
            I have a session bean calling the entity. The method is called like SessionBean.removeEntity(Pk pk); so I would have to call it twice ?

            I believe that my solution could be
            1) calling remove
            2) calling create
            3) if 2 fails call create again

            do you mean this ?

            I've found this article related to the problem: http://main.jboss.org/thread.jsp?forum=47&thread=6823. I also believe that it's a bug.

            • 3. Re: INSERTING AN ALREADY EXISTING BEAN
              daniela

              Hello Iviggiano,

              I mean you call two times from the client two different methods from the session bean. First you call the session bean for deleteing the data record. And second you call the session bean for re-insert the data record again. The entity bean is always the same. I think, that is clear.

              Do you understand what I mean now ?

              • 4. Re: INSERTING AN ALREADY EXISTING BEAN
                daniela

                Hello Iviggiano,

                On my jboss bug report was published a solution for your problem. Look on the following page:

                http://sourceforge.net/tracker/?func=detail&atid=376685&aid=504481&group_id=22866

                THX for your support
                Daniel

                • 5. Re: INSERTING AN ALREADY EXISTING BEAN
                  lviggiano

                  Thanks goes to you.
                  But I'm not deleting the bean manually from the db. I first call the remove() on the entity, then in insert it with the create(). And I do that in two different methods of a session bean, calling it in distinct actions by different JSP pages.

                  • 6. Re: INSERTING AN ALREADY EXISTING BEAN
                    jbossid

                    hi
                    iam developing one application in which i need to call aBMP from a stateless session bean.it seems u have worked on the same.
                    could you please post the ejb-jar.xml and jboss.xml
                    and sample code how u are calling BMP from session bean.
                    it would help me and some new bees like me.
                    thanks a lot

                    • 7. Re: INSERTING AN ALREADY EXISTING BEAN
                      fir99

                      Setting the commit-option to C is definitively a solution. I had the same problem with XDoclet 1.1.2 and JBoss 3.0.2. After creating a file
                      src\resources\xdoclet\jboss-container.xml
                      with the content

                      <container-configurations>

                      <container-configuration>
                      <container-name>Standard CMP 2.x EntityBean</container-name>
                      <commit-option>C</commit-option>
                      </container-configuration>

                      <container-configuration>
                      <container-name>Instance Per Transaction CMP 2.x EntityBean</container-name>
                      <commit-option>C</commit-option>
                      </container-configuration>

                      <container-configuration>
                      <container-name>Standard CMP EntityBean</container-name>
                      <commit-option>C</commit-option>
                      </container-configuration>

                      </container-configurations>

                      all works fine.

                      Bernhard