2 Replies Latest reply on Oct 4, 2002 9:29 AM by matthera

    yet another class cast exception

    gzhong

      I got this thrown at me when running a test example:

      Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList
      at $Proxy0.findByPrimaryKey(Unknown Source)
      at test.TestACL.getPlasmid(TestACL.java:111)


      The code to the simple getPlasmid() method is this:
      private static PlasmidData getPlasmid(int id) throws Exception{
      Context ctx = new InitialContext();
      Object ref = ctx.lookup("project/PlasmidData");
      System.out.println("Got object: "+ref);
      PlasmidDataHome home = (PlasmidDataHome)PortableRemoteObject.narrow(ref,PlasmidDataHome.class);
      System.out.println("Got home: "+home+" ("+home.getClass()+")");
      Object obj = home.findByPrimaryKey( new Integer(id));
      System.out.println(obj.getClass().getName());
      return (PlasmidData)obj;
      }

      The error above is thrown after the line "project/PlasmidDataHome (class $Proxy0)" was outputted. I turned on trace and I saw no errors thrown or printed out:
      2002-08-01 10:46:12,450 TRACE [org.jboss.ejb.plugins.LogInterceptor] Start method=findByPrimaryKey
      2002-08-01 10:46:12,450 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] Current transaction in MI is null
      2002-08-01 10:46:12,451 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] TX_REQUIRED for findByPrimaryKey
      2002-08-01 10:46:12,451 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] Thread came in with tx null
      2002-08-01 10:46:12,451 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] Starting new tx TransactionImpl:XidImpl [FormatId=257, GlobalId=mcrcr0.med.nyu.edu//78, BranchQual=]
      2002-08-01 10:46:12,452 TRACE [org.jboss.ejb.plugins.EntityInstancePool] Get instance org.jboss.ejb.plugins.EntityInstancePool@81b8f5e#true#class edu.nyu.rcr.bioinformatics.PlasmidDataBean
      2002-08-01 10:46:12,459 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.PlasmidData.findByPrimaryKey] Executing SQL: SELECT project_id FROM PLASMID_PROJECT WHERE project_id=?
      2002-08-01 10:46:12,461 TRACE [org.jboss.ejb.plugins.cmp.jdbc.JDBCFindByPrimaryKeyQuery.PlasmidData.findByPrimaryKey] Set parameter: index=1, jdbcType=INTEGER, value=62
      2002-08-01 10:46:12,840 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.PlasmidData.projectId] Get result: index=1, javaType=java.lang.Integer, Simple, value=62
      2002-08-01 10:46:12,842 TRACE [org.jboss.ejb.plugins.cmp.jdbc.ReadAheadCache.PlasmidData] Add finder results: entity=PlasmidData results=[62] readahead=[JDBCReadAheadMetaData : strategy=on-load, pageSize=255, eagerLoadGroup=*]
      2002-08-01 10:46:12,886 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] TxInterceptorCMT: In finally
      2002-08-01 10:46:12,887 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] TxInterceptorCMT:before commit of TransactionImpl:XidImpl [FormatId=257, GlobalId=mcrcr0.med.nyu.edu//78, BranchQual=]
      2002-08-01 10:46:12,893 TRACE [org.jboss.ejb.plugins.TxInterceptorCMT] TxInterceptorCMT:after commit of TransactionImpl:XidImpl [FormatId=257, GlobalId=mcrcr0.med.nyu.edu//78, BranchQual=]
      2002-08-01 10:46:12,893 TRACE [org.jboss.ejb.plugins.LogInterceptor] End method=findByPrimaryKey


      So I don't know where to look. The exception is thrown from inside the findByPrimaryKey method, so I have no control over that. I perused several times my xml config files, and if the problem is there, I don't see it. Isn't there a better way to debug? if there's a ClassCastException, wouldn't it help a bit more if I know what I am casting with and into?

      Thanks,
      G

        • 1. Re: yet another class cast exception
          dsundstrom

          What is the declaration of the findByPrimaryKey mehtod in the home interface. Are you trying to return a set and not the local (or remote) interface?

          • 2. Re: yet another class cast exception
            matthera

            Hello,

            I have the sample problem as this using jboss-3.0.2 on redhat7.0.

            My findByPrimaryKey method in the home interface declares the return type as a super interface of the local interface of the bean. i.e.

            public interface LocalBeanInterface extends LocalDecarledReturnIterface {
            }

            Am I allowed to do this. The EJB Spec says it doesn't support inheritance - but I though this only meant beans couldn't extend other beans...

            I also found this link while searching the web for similar problems, but I don't know if it's related:
            http://list.systinet.com/l/showmsg.xp?ln=systinet&mid=3456

            Please help, my project deadline is very close :(
            Mat