Skip to Content
avatar image
Former Member

ClassCastException in EJB lookup

Hi,

I developed an EJB in Netweaver and it is running fine together with my WebDynPro. Now i'm using the EJB as library file in my another Java standalone program that running using eclipse. I import it as External JAR into my application. When i try to run it, it will hit java.lang.ClassCastException. Here is my code.

...
try {
      Properties props = new Properties();
      props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
      props.put(javax.naming.Context.PROVIDER_URL, "localhost:50000");
      Context ctx = new InitialContext(props);
      TestHome home = (TestHome)ctx.lookup("SENDER");
      test = home.create();
}....

I got the error java.lang.ClassCastException error when i try to run it and the problem is in the TestHome home = (TestHome)ctx.lookup("SENDER");

I tried to change the code to

TestHome home = (TestHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("SENDER"), TestHome.class);

And also this way

Object obj = ctx.lookup("SENDER");
TestHome home = (TestHome)javax.rmi.PortableRemoteObject.narrow(obj, TestHome.class);

And i got this error which i think is the similar as both way is different syntax but same function type.

java.lang.ClassCastException
	at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
	at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
	at net.model.proxy.NewProxyClient$Polling.run(NewProxyClient.java:78)
	at java.util.TimerThread.mainLoop(Timer.java:432)
	at java.util.TimerThread.run(Timer.java:382)

I tried to google and check out SDN. Some said bout the classloader that cause this. I go through this document [How To ... EJB: Accessing EJB Applications using JNDI|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/0736159e-0301-0010-9ea4-c63d83d0797b] and follow it, but still having the problem ClassCastException. Any help for this? Appreciate for the helps. Thanks..

-


I tried to create a new Session Bean in my EJB application. Test it out, to my surprise it able to connect and create in my Java program. The session bean is empty. Then i tried to create a new Session bean with another name and JNDI, then copy the code into the new session bean. The same problem is occurs. So which mean some problem with my session bean. Will try to figure it out.

Edited by: Adrian Chan on May 5, 2009 12:32 PM

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    May 06, 2009 at 05:48 AM

    hi,

    is u r home object is located in local or remote

    if u keep in local -- as u refering one document u have to follow the

    example 3 on words

    let me know u need any futher info

    bvr

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      Actually now i'm debugging my Java application.

      I created another entity bean with a JNDI name. The entitybean don't have any function. It able to run the lookup function without any problem. I'm wonder this is java casting problem or my entitybean code?

      Thanks.

  • avatar image
    Former Member
    May 14, 2009 at 06:35 AM

    I did a terrible mistake.

    As i debugging the program then i realize that one of the JAR which is included in the EJB as reference project is not included in my Java program. After i include it then no problem with the program.

    Sorry for my big mistake and thanks for all the helps.

    Add comment
    10|10000 characters needed characters exceeded