on 11-20-2006 6:54 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"/> ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.