1 Reply Latest reply on Apr 30, 2002 10:19 AM by Dain Sundstrom

    ClassCastException checking if entity exists

    Frank Adcock Newbie

      I am trying to add an object to an entity bean using CMP which has a primary key class.

      I am getting a classCastException between leaving ejbCreate and prior to ejbPostCreate call. The stack trace is below the PK class code.

      Any clues ---


      import java.io.Serializable;
      public class PhoneNumber implements Serializable
      {
      public Long phoneNumber;
      public PhoneNumber()
      {
      }
      public PhoneNumber(Long num)
      {
      setPhoneNumber( num);
      }
      public Long getPhoneNumber()
      {
      return this.phoneNumber;
      }
      public void setPhoneNumber(Long num)
      {
      this.phoneNumber = num;
      }
      public boolean equals(Object rhs)
      {
      if( !(rhs instanceof PhoneNumber) )
      return false;
      PhoneNumber pk = (PhoneNumber)rhs;
      return phoneNumber == pk.getPhoneNumber();
      }
      public int hashCode()
      {
      return phoneNumber.hashCode();
      }
      public String toString()
      {
      return phoneNumber.toString();
      }
      }


      2002-04-30 15:37:53,677 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.NumberStatus.findByPrimaryKey] Executing SQL: SELECT status FROM NUMBERSTATUS WHERE status=?
      2002-04-30 15:37:53,692 INFO [STDOUT] Status is : ejb/numbers/Status:UnAvailable
      2002-04-30 15:37:53,692 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCLoadEntityCommand.NumberStatus] Executing SQL: SELECT expireStatus, expirePool, expiry FROM NUMBERSTATUS WHERE (status=?)
      2002-04-30 15:37:53,692 INFO [STDOUT] Status expires in 0 days
      2002-04-30 15:37:53,692 INFO [STDOUT] Status changed
      2002-04-30 15:37:53,692 INFO [STDOUT] NumberBean::ejbCreate leaving
      2002-04-30 15:37:53,708 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Numbers] Create: pk=402302067
      2002-04-30 15:37:53,708 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Numbers] Executing SQL: SELECT COUNT(*) FROM NUMBERS WHERE phoneNumber=?
      2002-04-30 15:37:53,708 ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.Numbers] Error checking if entity exists
      java.lang.ClassCastException: com.whitesmiths.sacha.ejb.numbers.interfaces.PhoneNumber
      at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2367)
      at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2462)
      at org.jboss.resource.adapter.jdbc.local.PreparedStatementInPool.setObject(PreparedStatementInPool.java:534)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCUtil.setParameter(JDBCUtil.java:156)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setArgumentParameters(JDBCAbstractCMPFieldBridge.java:283)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCAbstractCMPFieldBridge.setPrimaryKeyParameters(JDBCAbstractCMPFieldBridge.java:271)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCEntityBridge.setPrimaryKeyParameters(JDBCEntityBridge.java:522)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.entityExists(JDBCCreateEntityCommand.java:151)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.execute(JDBCCreateEntityCommand.java:127)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:444)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:253)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:231)
      at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:728)
      at java.lang.reflect.Method.invoke(Native Method)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1111)
      at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:73)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:230)