ClassCastException trying to access an EJB in Oracle9I


EJB design: ClassCastException trying to access an EJB in Oracle9I

  1. Hi,

    I have done remote lookup using the RMIInitialContextFactory from a Thread program.

    I am able to get the JNDI object(Object obj=context.lookup("abc");), but unable to type cast it to the home object type. When i type cast using PortableRemoteObject.narrow() it throws a ClassCastException.

    Can anyone pls help me out for this problem.

    Thanx in advance

  2. Try printing out what the actual class is:

  3. Hi,

    My actual Home interface is ABCHome but what it returns from the PortableRemoteObject.narrow is ABCJndiEJBHome.

    Any clue for this one.
  4. If sounds like you are getting the auto-generated stub for your home interface (which should be correct). Here are some more debugging ideas:

    1. Try printing out the interfaces of the ABCJndiEJBHome so make sure that in fact it implements your ABCHome interface.

    Class[] interfaces = obj.getClass().getInterfaces();
    for (int i=0; i<interfaces.length, i++) {

    2. Double check your configuration information in your ejb-jar.xml file to make sure you are specifying the home interface correctly.

    Beyond that, I have not got a clue.
  5. Hi,

    The same code when i try to use it in an Application Client works fine for me.
    I use ApplicationInitialContextFactory instead of RMIInitialContextFactory.
    This works fine and i am able to handle with the EJB.