cancel
Showing results for 
Search instead for 
Did you mean: 

ClassCastException in ctx.lookup

Ronib
Participant
0 Kudos

Hello,

I created java bean and deployed it to server with an EAR project.

Now I want to write java client to access it and the code

<i>TestBeanLocalHome y = (TestBeanLocalHome) ctx.lookup("sap.com/EJBTestEAR/TestBeanBean");</i>

gives me ClassCastException.

The same with code <i>TestBeanLocalHome myExampleHome =

(TestBeanLocalHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("sap.com/EJBTestEAR/TestBeanBean"), TestBeanLocalHome.class);</i>

i will appreciate any help on that matter

Roni

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Roni,

Try to get a remote reference of the bean instead of local reference using the following code..

TestBeanHome home = (TestBeanHome) ctx.lookup("sap.com/EJBTestEAR/TestBeanBean");

TestBeanRemote remote = home.create();

Using local interfaces may not work if you have deployed the bean in remote server.

Regards,

Uma

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Roni,

Please make sure that your ejb-jar.xml and j2ee-engine.xml are proper and reflect proper JNDI names.After deploying the ear, pls check the JNDI tree using Visual Admin. Use narrow() method to get handle of Home.

regards,

Sujesh

Former Member
0 Kudos

Check if you can log on to the Visual administrator and have a look at the JNDI registry. This is to make sure if your bean is first of all bound in the JNDI registry. If you see your bean listed there then it is always better to use this code

TestBeanLocalHome myExampleHome = 
(TestBeanLocalHome)javax.rmi.PortableRemoteObject.narrow(ctx.lookup("sap.com/EJBTestEAR/TestBeanBean"), TestBeanLocalHome.class);

Former Member
0 Kudos

You need to really look into JNDI setup.

You are probably not calling up the right bean or not casting to the right interface... In your case it looks like your are retrieving the Home interface and not LocalHome...

Enjoy