1 Reply Latest reply on Jun 24, 2002 6:09 PM by dsundstrom

    cmp relationship in ejb 1.1

    jlisle

      Hi all. I hope this doesn’t repeat previous discussions, but I couldn’t find what I was looking for.

      We have a J2EE project that we’re trying to migrate to Jboss. We have been using CMP 1.1 with Orion 1.3.8 as our application server. We aren’t ready to use CMP 2.0 but have run into problems with relationships.

      We have an entity bean named “Worker” that uses a single Integer as its primary key. It has several CMP fields that are doubles and Strings. In addition, it references two other entity beans, “CostReference” and “LocationMaster”. Their primary keys are also Integers. The CMP fields for “Worker” are shown below:

      public Integer workerId;
      public String name;
      public String password;
      public String employeeNum;
      public double payRate;
      public CostReference costReferenceId;
      public LocationMaster locationId;


      With the Orion Application Server, using EJB CMP 1.1, the primary keys of “CostReference” and “LocationMaster” were persisted to the database automatically. I assume this is referred to as a 1:1 relationship.

      We can succesfully deploy our *.ear on JBoss 3.0. We have custom finder methods that are stored in various jaws.xml files (for cmp 1.1). We can successfully get a remote reference to the correct “Worker” entity bean. However, when we call a method on that bean, we get the following stack trace:

      2002-06-24 13:58:43,167 DEBUG [org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand] Load command executing: SELECT Worker.workerId,Worker.name,Worker.activeFlag,Worker.employeeNum,Worker.modifiedDate,Worker.costReferenceId,Worker.modifiedByUserId,Worker.createDate,Worker.locationId,Worker.password_,Worker.payRate,Worker.createdByUserId FROM Worker WHERE workerId=?
      2002-06-24 13:58:43,167 DEBUG [org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand] Set parameter: idx=1, jdbcType=INTEGER, value=11005
      2002-06-24 13:58:43,167 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackException, causedBy:
      java.rmi.ServerException: Load failed; nested exception is:
      java.lang.NullPointerException
      java.lang.NullPointerException
      at java.lang.reflect.Field.set(Native Method)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.setCMPFieldValue(JDBCCommand.java:669)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCLoadEntityCommand.loadOneEntity(JDBCLoadEntityCommand.java:229)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCLoadEntityCommand.handleResult(JDBCLoadEntityCommand.java:188)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCQueryCommand.executeStatementAndHandleResult(JDBCQueryCommand.java:63)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCCommand.jdbcExecute(JDBCCommand.java:175)
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCLoadEntityCommand.execute(JDBCLoadEntityCommand.java:159)
      at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.loadEntity(JAWSPersistenceManager.java:283)
      at org.jboss.ejb.plugins.CMPPersistenceManager.loadEntity(CMPPersistenceManager.java:410)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.loadEntity(CachedConnectionInterceptor.java:353)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:310)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:193)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:107)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:96)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:167)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:61)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:129)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:166)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.Container.invoke(Container.java:705)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:73)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:76)
      at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:116)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
      at $Proxy187.getDetails(Unknown Source)
      at
      ...........

      As I mentioned earlier, we aren’t ready to use the container managed relationships (CMR) of EJB 2.0.

      How can we have entity beans with cmp fields that are other entity beans?

      Thanks for your help.

      Josh

        • 1. Re: cmp relationship in ejb 1.1
          dsundstrom

          It looks like Orion is doing something very non-compliment. The way to safely persist an Entity reference is to serialize the EJBHandle, and it looks like Orion is doing pk storage. If you want this mapping, you will have do the following (which is complient):

          Change the type of the current cmp field to the pk type of the related entity (Integer in you case).

          Change the getter method to do a findByPrimaryKey on the related entity's home with the value of the fk field. (You don't have to wory about caching JBoss won't touch the db if the pk is in the cache).

          Change the setter to get the pk and set it to the fk field.


          This is fairly simple and spec complient.