cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.ClassCastException in local lookups

Former Member
0 Kudos

hi,

i have written two ejb projects named as proj1 and proj2.

i deployed proj1 as EAR1 and proj2 as EAR2.(in same server)

in proj1 Sessionbean1 i need to use(lookup) proj2 Sessionbean2 .

<b>i have given jndi name for proj2 Sessionbean2 as "jndiproj2"</b>

InitialContext ic=new InitialContext();
Sessionbean2LocalHome home=(Sessionbean2LocalHome)ic.lookup("localejbs/jndiproj2");

while i am running this application i am getting java.lang.ClassCastException.

(this application is working fine if i deployed both proj1 and proj2 together as single EAR)

regards

Guru

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Have you ever connected to your SAP J2EE Engine using the Visual Administrator? If so, you can go to Server->Service->JNDI Registry and look under the localejbs for the actual name that would work in the lookup method.

It appears to me that you are missing the vendor. If you have not specified a vendor in the application-j2ee-engine.xml, then it is by default "sap.com", then your ejb application name, then you EJB name.

I have created a bean SurveyReportsBean with my SurveyApp with the vendor of pcbp.com. My lookup would be:

"localejbs/pcbp.com/SurveyApp/SurveyReportsBean"

Hope this helps.

Former Member
0 Kudos

Narrowing is necessary when client and bean run in different JVM's.

Guruvulu, do you have reference (in .dcdef) from EAR1 to EAR2 (or from EAR1 to proj2) with

<at-runtime qualifier="strong"/> ?

former_member182294
Active Contributor
0 Kudos

Hi,

You need to narrow the object reference. Check the following code..

InitialContext ic=new InitialContext();

Object homeObj = ic.lookup("localejbs/jndiproj2");

Sessionbean2LocalHome home=(Sessionbean2LocalHome)javax.rmi.PortableRemoteObject.narrow(homeObj ,Sessionbean2LocalHome .class);

Regards

Abhilash

Former Member
0 Kudos

Hi,

this problemm appears due to class loading problem.

To solve it try:

ClassLoader nativeClassLoader = Thread.currentThread().getContextClassLoader();

try {

Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());

InitialContext ic=new InitialContext();

Sessionbean2LocalHome home=(Sessionbean2LocalHome)ic.lookup("localejbs/jndiproj2");

} finally{

Thread.currentThread().setContextClassLoader(nativeClassLoader);

}

Former Member
0 Kudos

Hi ,

still it is showing the same error.

Regards,

Guru

Vlado
Advisor
Advisor
0 Kudos

Hi Guru,

I suppose you have the interfaces of Sessionbean2 in EAR1. Please remove them and add reference to EAR2 in the application-j2ee-engine.xml of EAR1.

btw, the recommended standard way for accessing an EJB from another EJB is by declaring an ejb-ref (ejb-local-ref) in the ejb-jar.xml and using the "java:comp/env/" namespace.

Best regards,

Vladimir

Former Member
0 Kudos

HI,

i am having trouble accessing an EJB from another EJB by declaring an ejb-ref (ejb-local-ref) in the ejb-jar.xml and in ejb-j2ee-engine.xml. when using the "java:comp/env/" namespace the values are looked under webcontainer and not from ejbcontainer or ebjcontext. The EJB reference name(e.g: XXX) i have given under ejb-jar.xml appears inside VisualAmin/JNDI Registry/ejbContexts.

how can i access from EJB. XXX

Object o =context.lookup("java:comp/env/XXX");

thanks

sowmiya