Help - Classcast Exception

Discussions

EJB programming & troubleshooting: Help - Classcast Exception

  1. Help - Classcast Exception (1 messages)

    Hai all.,
       I using the Weblogic Server to deploy my EJB.I deployed a Simple Stateless session bean in that.When i invoke the n=bean from the servlet i am getting ClassCast Exception at the Lookup method. Here is the sample code.

    InitialContext ctx = new InitialContext();
    Object objRef = ctx.lookup("Order");
    CustOrderHome homeCust = (CustOrderHome)PortableRemoteObject.narrow(objRef,CustOrderHome.class);

    I am getting the Exception at the Line 2.
    Can anybody help ???
    Thanks in advance
    Sundhar





  2. Help - Classcast Exception[ Go to top ]

    ctx.lookup wll return ahome object which u need to specifically typecast so try using the following line of code :

    InitialContext ctx = new InitialContext();
    CustOrderHome homeCust = (CustOrderHome)ctx.lookup("Order");

    or

    InitialContext ctx = new InitialContext();
    Object objRef = (Object)ctx.lookup("Order");
    CustOrderHome homeCust = (CustOrderHome)PortableRemoteObject.narrow(objRef,CustOrderHome.class);

    or

    InitialContext ctx = new InitialContext();
    Object objRef = (CustOrderHome)ctx.lookup("Order");
    CustOrderHome homeCust = (CustOrderHome)PortableRemoteObject.narrow(objRef,CustOrderHome.class);