3

I have created a EJB2.0 using Eclipse 3.7 IDE, and deployed it in JBoss 5 application server (my bean name is product). I am doing normal context lookup (and other stuff to call ejb), and I am able to call EJB successfully. Now my question is what is JNDI name exactly, and where did it get used in all this. Is my bean name the JNDI name, or is this my JNDI name -> org.jnp.interfaces.NamingContextFactory. Where is the JNDI name in this????? my code:-

// initial code.............
Context  ctx = getContext();
Object obj=ctx.lookup("Product");
ProductHome home =(ProductHome)  javax.rmi.PortableRemoteObject.narrow(obj,ProductHome.class);
ProductRemote remote=home.create();

Product prd = new rohit.Product("PRDCamera",001,50.50) ;
remote.addProduct(prd);
remote.updateProduct(prd);
remote.removeProduct(001);
remote.findProduct(001);
remote.findAllProduct();


// getContext Method

public static InitialContext getContext() throws Exception{
    Properties pro = new Properties();
    pro.put(javax.naming.InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
    pro.put(javax.naming.InitialContext.PROVIDER_URL,"localhost:1099");
    return new InitialContext(pro);
}
Community
  • 1
  • 1
Rohit Elayathu
  • 611
  • 6
  • 12
  • 26

1 Answers1

3

There is no JNDI name in your code.

This is how you look up EJBs in EJB 2.0:

Object ejbHome = initialContext.lookup("java:comp/env/com/mycorp/MyEJB");

MyHome myHome = (MyHome)javax.rmi.PortableRemoteObject.narrow(
  (org.omg.CORBA.Object)ejbHome, MyHome.class);

The JNDI name is java:comp/env/com/mycorp/MyEJB in this case.

In the much saner EJB 3.0, you just do

MyEJB myEJB = initialContext.lookup("java:comp/env/com/mycorp/MyEJB")

and do away with the terrible home interface idea.

Ingo Kegel
  • 42,759
  • 9
  • 65
  • 97
  • Ok thanks a lot. So is this JNDI name specific to server. Like if I am using JBoss or WEBLogic Server, JNDI names would be different for these two servers, right ? And what is "org.jnp.interfaces.NamingContextFactory" used in getContext method (above in my code) ?? – Rohit Elayathu Mar 19 '12 at 05:10
  • @RohitElayathu No, that JNDI name is standardized, it is java:comp/env/com/mycorp/MyEJB for an EJB with class com.mycorp.MyEJB by default. The implementation class of the initial context factory, however, is proprietary. – Ingo Kegel Mar 19 '12 at 09:04
  • This is how code is in the file i am referring `public final static String JNDI_NAME="myproj/Status"; public final static String EJB_NAME="myprojStatus";` **Here Status is an Interface, and should i create a directory named myproj and place Status Interface in it. Is the JNDI_NAME a path???** – JavaDragon Oct 10 '15 at 06:12