Skip to Content
Former Member
Nov 10, 2005 at 05:01 PM

Class cast exception when fetching EJB


This code:

Object o = ctx.lookup("java:comp/env/ejb/AdderEJB");
AdderLocalHome home = (AdderLocalHome)o;

generates a ClassCastException. The object returned from the JNDI lookup is something like com.example.ejb.AdderLocalHomeImpl0@1374bef, and I'm trying to cast it to the interface com.example.ejb.AdderLocalHome.

The local reference to the EJB is as follows:


Why am I getting a casting exception? I believe I'm following the documented methods correctly, but I must be doing something wrong.

BTW, this EJB has also been exposed via a web service, and that functions correctly, so I know the EJB is correctly configured and deployed.