aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Problem Accessing Local EJB!!!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem Accessing Local EJB!!!!!!" Watch "Problem Accessing Local EJB!!!!!!" New topic
Author

Problem Accessing Local EJB!!!!!!

Gaurav Jain
Ranch Hand

Joined: Mar 11, 2004
Posts: 108
I am calling a local stateless session bean from a stateless session bean of remote type.
During look up for the local bean i am getting this error
javax.naming.NameNotFoundException: Context: localhost/nodes/localhost/servers/server1, name: ejb/cbsejb/CBSLocalHome: First component in name CBSLocalHome not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL mg.org/CosNaming/NamingContext/NotFound:1.0]
Whats the problem??
I am using WSAD5.1.1
Roland Barcia
author
Ranch Hand

Joined: Apr 15, 2004
Posts: 181
Have you set up a Local EJB Resource Reference on the calling Session Bean to the other Bean you are calling?


Roland Barcia: IBM Distinguished Engineer, CTO Mobile for Lab Services
Gaurav Jain
Ranch Hand

Joined: Mar 11, 2004
Posts: 108
Yes i have done it the EJB deployment descriptor in the references tab but the problem still persists.
Just to clarify my parent bean calling bean is CBSSession whic is of remote type and my target bean which is local is CBS and i have set up the reference on CBSSession.
Is that correct?
Roland Barcia
author
Ranch Hand

Joined: Apr 15, 2004
Posts: 181
You need to make sure you are using the <ejb-loc-ref> tag. Also, to use references, make sure you are pre-qualifiying your lookups with java:comp/env
Gaurav Jain
Ranch Hand

Joined: Mar 11, 2004
Posts: 108
I tried whatever you had told but now i am getting the following error:
javax.naming.NameNotFoundException: Name comp/env/ejb/cbsejb not found in context "java:".
I am doing the lookup in the following manner:
InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/ejb/cbsejb/L2LocalHome");
CBSLocalHome objHome = (CBSLocalHome)obj;
CBSLocal objLocal = objHome.create();
objLocal.accessLocal(sUserId);
Roland Barcia
author
Ranch Hand

Joined: Apr 15, 2004
Posts: 181
Did you bind your reference to the real JNDI name your EJB is defined to. If you are using the EJB DD editor, what value do you have for WebSphere Binding for the reference and is it the same as the binding on the Bean tab for the Local EJB.
Gaurav Jain
Ranch Hand

Joined: Mar 11, 2004
Posts: 108
Roland,
It worked,however i din not have to specify any EJB Resource reference tag,all i did was looked up the bean using the following:
local:ejb/<jndi name>
Roland Barcia
author
Ranch Hand

Joined: Apr 15, 2004
Posts: 181
Ok, however, using Resource References will keep the Java Code Portable and is rececomended. Your code now has WebSphere specific namespace in the code when Resources References should hide that from the code.
Seetesh Hindlekar
Ranch Hand

Joined: Feb 13, 2004
Posts: 244
Hi Gaurav,
I tried the same using Weblogic 7.0. No issues there.
I had written the lookup of the Local Session Bean in one of the business methods of the Remote one. Snippet of the code and both the xml is mentioned below.
Rgds,
Seetesh
public class PlayerBean implements SessionBean
{
......
public String playercall()
{
try
{
Context ic= new InitialContext();
erHome= (ERHome) ic.lookup("JNDIERLocal");
System.out.println("SEETESH 1 : CREATING ER FROM PLAYER");
er = erHome.create();
//er = (ER) PortableRemoteObject.narrow(erHome.create(),ER.class);
System.out.println("SEETESH 2 : CREATED ER FROM PLAYER BEFORE CALLING DISPLAYSEET");
String aaa = er.displaySeet();
System.out.println("SEETESH 3 : AFTER CALLING DISPLAYSEET aaa : "+aaa);
return "success";
}
ejb-jar.xml
-----------
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC
'-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN'
'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>PlayerEJB</ejb-name>
<home>ejb.stateless.er.PlayerHome</home>
<remote>ejb.stateless.er.Player</remote>
<ejb-class>ejb.stateless.er.PlayerBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>WEBL</env-entry-name>
<env-entry-type>java.lang.Double </env-entry-type>
<env-entry-value>10.0</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>INTL</env-entry-name>
<env-entry-type>java.lang.Double </env-entry-type>
<env-entry-value>15.0</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>playerLimit</env-entry-name>
<env-entry-type>java.lang.Integer </env-entry-type>
<env-entry-value>100</env-entry-value>
</env-entry>
</session>
<session>
<ejb-name>EREJB</ejb-name>
<local-home>ejb.stateless.er.ERHome</local-home>
<local>ejb.stateless.er.ER</local>
<ejb-class>ejb.stateless.er.ERBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>erLimit</env-entry-name>
<env-entry-type>java.lang.Integer </env-entry-type>
<env-entry-value>300</env-entry-value>
</env-entry>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>PlayerEJB</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>EREJB</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
<ejb-client-jar>ejb20_SB_local_remote.jar</ejb-client-jar>
</ejb-jar>
weblogic-ejb-jar.xml
---------------------
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC
'-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN'
'http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd'>
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>PlayerEJB</ejb-name>
<jndi-name>JNDIPlayer</jndi-name>
</weblogic-enterprise-bean>
<weblogic-enterprise-bean>
<ejb-name>EREJB</ejb-name>
<local-jndi-name>JNDIERLocal</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
Roland Barcia
author
Ranch Hand

Joined: Apr 15, 2004
Posts: 181
You don't have to use Resource References, but it is recomended. The J2EE spec does not define how to bind an EJB to the real namespace. So WebLogic uses 2 different names in its weblogic-ejb.xml for each Bean type: Local or Remote. WAS binds the EJB to on JNDI name even if it has both a Remote and Local Interface. Inside of WAS, it will be pre-qualified with local:. But if you define a <ejb-loc-ref> and bind it to the JNDI name of the Local EJB, then it will automatically use the local interface based on the <ejb-loc-ref> tag. Although you may get similar code to work in 1 or 2 app servers, resource references are guaranteed to work in any app server.
 
jQuery in Action, 2nd edition
 
subject: Problem Accessing Local EJB!!!!!!