1 Reply Latest reply on Jan 23, 2002 8:32 AM by adrian.brock

    ClassCastException occurred performing lookup()

    lbasili

      Hello,
      I wrote a class, called InterbaseServiceProvider, that binds a jdbc interbase datasource to a context.
      I wrote an entity bean, called CustomerBean, that uses this datasource to handle its (bean managed) persistence.

      When, inside the ejbCreate() method, I try to perform a lookup() on naming context and to assign the retrieved object to a variable of type javax.sql.DataSource, a ClassCastException exception is thrown:
      here is the relevant part of the stack trace:

      java.lang.ClassCastException: javax.naming.Reference
      at ztc.ejb.CustomerBean.ejbCreate(Unknown Source)
      ...

      I tried to use PortableRemoteObject.narrow() method but the behavior is the same.

      I printed on screen the results of obj.toString() method, and I found that it is a javax.naming.Reference instance that contains the properties to create db connections.

      I have jdk1.3.1, and these are the jars included in classpath that I use to compile/execute the code that invoke bind() (InterbaseServiceProvider), and the code that invokes lookup (CustomerBean)

      ${interbase.libs}\interclient.jar;
      ${jboss.libs}\jaas.jar;
      ${jboss.libs}\jboss-client.jar;
      ${jboss.libs}\jboss-j2ee.jar;
      ${jboss.libs}\jbosssx-client.jar;
      ${jboss.libs}\jboss-jdbc_ext.jar;
      ${jboss.libs}\jndi.jar;
      ${jboss.libs}\jnp-client.jar;

      This is the common to both jndi.properties file:
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.provider.url=localhost:1099
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

      This is a code portion of InterbaseServiceProvider
      javax.sql.DataSource dataSource = new interbase.interclient.DataSource ();
      // datasource initialization
      // ...
      // ...
      javax.naming.Context context = new javax.naming.InitialContext ();
      System.out.println ("got context");
      try{
      context.createSubcontext("jdbc");
      }catch(javax.naming.NameAlreadyBoundException nabe){

      }catch(Exception exc){
      exc.printStackTrace();
      }
      context.rebind ("jdbc/ztc", dataSource);

      This is the code with which I lookup into into CustomerBean.ejbCreate

      // env is properly initialized
      InitialContext ic = new InitialContext(env);
      Object obj = ic.lookup("jdbc/ztc");
      javax.sql.DataSource ds = (javax.sql.DataSource)obj;


      the last row throws the exception I mentioned.
      Is it a configuration-related problem ? Wrong classpath that load incompatible classes ?
      Please, help me.
      Thank you in advance
      Ludovico Basili


        • 1. Re: ClassCastException occurred performing lookup()

          I'm not sure I totally follow what you are doing.

          You are binding a datasource from a client?
          Then trying to access this using an ejb.

          JBoss in the default configuration doesn't install a
          security manager so it will not "download" classes
          when you do PortableRemoteObject.narrow().
          Are you specifying an rmi codebase anyway?

          The cast (DataSource)obj is definitly wrong.

          Try adding the interbase jar into lib/ext
          this will make the classes available to the ejb
          if this is the problem. You will need to reboot the
          server to get the new jar.

          This isn't the normal way of specifying the database.
          It is normally configured in jboss.jcml so the
          server manages the database connection pooling, transactions etc.

          Try asking in the database forum, you might get some
          more expert help than mine for database configuration.

          Regards,
          Adrian