ClassCastException occurred performing lookup()
lbasili Jan 23, 2002 7:13 AMHello,
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