1 Reply Latest reply on Apr 3, 2003 10:30 AM by Michael Wolf

    NoSuchObjectLocalException in ejbPostCreate

    Michael Wolf Newbie

      I have a CMP 2.0 Entity Bean deployed to JBoss 3.2RC4. The bean has two 1-1 CMR's which are populated in the ejbPostCreate method of the bean.

      The problem I'm encountering is that JBoss seems to be using a cached primary key in the ejbPostCreate when working with the CMRs. I have a simple test which adds an instance of of the Entity with its CMR fields set. What happens is that for the first test I run, the bean is created correctly with the proper CMR relationships; however, every additional run of the test, updates the database row from the first test instead of the row created by the current test. Also, if I manually delete the first row from the database, the next test I run will fail with a NoSuchObjectLocalException in ejbPostCreate. If you look at the logging code below, you'll see that the primary key I've read from the entityContext differs from the primary key reported by the exception. Can anyone suggest why this might be occuring?

      Here is the code for the ejbCreate and ejbPostCreate methods along with the relevant log messages.

      /**
      * @ejb.create-method
      */
      public String ejbCreate(Employee employee) throws ValidationException, CreateException {
      logMethodEnter();
      try {
      //First validate the address
      employee.validate();

      setOid(getNextUID());
      setFirstName(employee.getFirstName());
      setMiddleName(employee.getMiddleName());
      setLastName(employee.getLastName());

      return null;
      } catch (ValidationException ve) {
      entityContext.setRollbackOnly();
      throw ve;
      } finally {
      logMethodExit();
      }
      }
      public void ejbPostCreate(Employee employee) throws ValidationException, CreateException {
      //Now handle the dependent objects
      try {
      debug("PostCreate pk: " + entityContext.getPrimaryKey());
      debug("PostCreate oid: " + getOid());

      //Retrieve the appropriate local interface for the EthnicGroup and populate the field
      //We assume that the group already exists
      EthnicGroupLocal ethnicGroupLocal = EthnicGroupUtil.getLocalHome().findByPrimaryKey(new Integer(employee.getEthnicGroup().getID()));
      setEthnicGroup(ethnicGroupLocal);

      //Create the address and link it to the user
      AddressLocal addressLocal = AddressUtil.getLocalHome().create(employee.getAddress());
      setAddress(addressLocal);
      } catch (ValidationException ve) {
      entityContext.setRollbackOnly();
      throw ve;
      } catch (FinderException fe) {
      throw new EJBException(fe);
      } catch (NamingException ne) {
      throw new EJBException(ne);
      } catch (CreateException ce) {
      throw new EJBException(ce);
      }
      }



      17:13:44,704 {us.oh.state.dot.ucp.ejb.beans.EmployeeCMP$Proxy.flow} ejbCreate - Exit Method
      17:13:44,714 {us.oh.state.dot.ucp.ejb.beans.EmployeeCMP$Proxy} ejbPostCreate - PostCreate pk: B9576CE37EC5E8F69D9D5FDC300E1050F90436ED
      17:13:44,714 {us.oh.state.dot.ucp.ejb.beans.EmployeeCMP$Proxy} ejbPostCreate - PostCreate oid: B9576CE37EC5E8F69D9D5FDC300E1050F90436ED
      17:13:44,734 {org.jboss.ejb.plugins.LogInterceptor} handleException - TransactionRolledbackLocalException, causedBy:
      javax.ejb.NoSuchObjectLocalException: Entity not found: primaryKey=EC40229D43BD671FB85305E2232571F8FA65A27D
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:158)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:273)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:198)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      at org.jboss.ejb.EntityContainer.internalInvoke(EntityContainer.java:483)
      at org.jboss.ejb.Container.invoke(Container.java:678)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.invokeRemoveRelation(JDBCCMRFieldBridge.java:873)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.createRelationLinks(JDBCCMRFieldBridge.java:727)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setInstanceValue(JDBCCMRFieldBridge.java:660)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setValue(JDBCCMRFieldBridge.java:538)
      at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:126)
      at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
      at us.oh.state.dot.ucp.ejb.beans.EmployeeCMP$Proxy.setEthnicGroup()
      at us.oh.state.dot.ucp.ejb.beans.EmployeeEJB.ejbPostCreate(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.plugins.CMPPersistenceManager.postCreateEntity(CMPPersistenceManager.java:260)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.postCreateEntity(CachedConnectionInterceptor.java:278)
      at org.jboss.ejb.EntityContainer.postCreateLocalHome(EntityContainer.java:585)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1032)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:95)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:295)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:82)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:174)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:89)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:43)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:92)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:123)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
      at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:477)
      at org.jboss.ejb.Container.invoke(Container.java:698)
      at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:272)
      at org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
      at $Proxy40.create(Unknown Source)
      at us.oh.state.dot.ucp.ejb.beans.CompanyManagementEJB.addEmployee(Unknown Source)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:629)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:104)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:117)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:198)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:322)
      at org.jboss.ejb.Container.invoke(Container.java:678)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:358)
      at java.lang.reflect.Method.invoke(Native Method)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:236)
      at sun.rmi.transport.Transport$1.run(Transport.java:147)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:143)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)