cancel
Showing results for 
Search instead for 
Did you mean: 

Class cast exception when fetching EJB

Former Member
0 Kudos

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:

<server-component-ref>
		<description>
		</description>
		<name>ejb/AdderEJB</name>
		<type>interface</type>
		<jndi-name>localejbs/example.com/test-ear/AdderBean</jndi-name>
</server-component-ref>

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.

Ideas?

Accepted Solutions (1)

Accepted Solutions (1)

viliana
Advisor
Advisor
0 Kudos

Hi Ken,

This is not the correct way to declare local EJB references. Please, try to follow this documentation:

<a href="http://help.sap.com/saphelp_nw04s/helpdata/en/38/3e5a4201301453e10000000a155106/frameset.htm">http://help.sap.com/saphelp_nw04s/helpdata/en/38/3e5a4201301453e10000000a155106/frameset.htm</a>

The server-component-ref element can be used to access functionality provided by a J2EE Engine service for example, but should not be used to access another EJB.

Best regards,

Viliana

Former Member
0 Kudos

Thanks Viliana, for the pointer. Once I cleaned up my web.xml and application-j2e-engine.xml to follow the documentation, it worked just fine.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ken,

From where are you calling EJB?

If you are calling this EJB from another EJB of the same project then it is fine. But, if you are calling from another application then try to use Remote interface of your EJB home instead of using local interface.

Regards,

Bhavik