title: How to access EJB using JNDI Weblogic
body: <p>Hello I am trying to access EJB component using JNDI. For this i made a simple program called HelloWorld.</p>
  
  <p>Remote Interface </p>
  
  <pre><code>public interface HelloWorldEJB extends EJBObject {
      public String sayHello() throws RemoteException;
  
  }
  </code></pre>
  
  <p>Home Interface</p>
  
  <pre><code>public interface HelloWorldEJBHome extends EJBHome {
      HelloWorldEJB create() throws RemoteException, CreateException;
  }
  </code></pre>
  
  <p>Implmentation </p>
  
  <pre><code>public class HelloWorldEJBBean implements SessionBean {
      private SessionContext _context;
  
      public void ejbCreate() {
      }
  
      public void setSessionContext(SessionContext context) throws EJBException {
          _context = context;
      }
  
      public void ejbRemove() throws EJBException {
      }
  
      public void ejbActivate() throws EJBException {
      }
  
      public void ejbPassivate() throws EJBException {
      }
  
      private Object getEntityByDTO(Object entityDTO) throws FinderException,
                                                             NamingException {
          return null;
      }
  
      public String sayHello(){
          return "Hello";
       }
  }
  </code></pre>
  
  <p>ejb-jar.xml</p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'windows-1252'?&gt;
  &lt;ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
           version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee"&gt;
    &lt;enterprise-beans&gt;
      &lt;session&gt;
        &lt;description&gt;Session Bean ( Stateless )&lt;/description&gt;
        &lt;display-name&gt;HelloWorldEJB&lt;/display-name&gt;
        &lt;ejb-name&gt;HelloWorldEJB&lt;/ejb-name&gt;
        &lt;home&gt;model.HelloWorldEJBHome&lt;/home&gt;
        &lt;remote&gt;model.HelloWorldEJB&lt;/remote&gt;
        &lt;ejb-class&gt;model.HelloWorldEJBBean&lt;/ejb-class&gt;
        &lt;session-type&gt;Stateless&lt;/session-type&gt;
        &lt;transaction-type&gt;Container&lt;/transaction-type&gt;
      &lt;/session&gt;
    &lt;/enterprise-beans&gt;
    &lt;assembly-descriptor&gt;
      &lt;container-transaction&gt;
        &lt;method&gt;
          &lt;ejb-name&gt;HelloWorldEJB&lt;/ejb-name&gt;
          &lt;method-name&gt;*&lt;/method-name&gt;
        &lt;/method&gt;
        &lt;trans-attribute&gt;Required&lt;/trans-attribute&gt;
      &lt;/container-transaction&gt;
    &lt;/assembly-descriptor&gt;
  &lt;/ejb-jar&gt;
  </code></pre>
  
  <p>Client Lookup program</p>
  
  <pre><code>DataSource dataSource = null;
  try {
      String ejburl = "t3://localhost:7101/";
      /**Setup the environment*/
      Hashtable environment = new Hashtable(6);
      /**Turn JNDI on to Weblogic and use oracle db password verification*/
      environment.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
      environment.put(Context.SECURITY_PRINCIPAL, "weblogic");
      environment.put(Context.SECURITY_CREDENTIALS, "weblogic1");
      environment.put(Context.PROVIDER_URL, ejburl);
  
      Context context = new InitialContext(environment);
     method -1 Object obj = context .lookup("HelloWorld10g");
     method -2  Object obj2 = context .lookup("HelloWorld10gModelEJB_jarHelloWorldEJB_EO");
      System.out.println("JNDI Done");
      method -3 context.lookup("HelloWorldEJB#model.HelloWorldEJB");
  } catch (Exception ex) {
      ex.printStackTrace();
  }
  </code></pre>
  
  <p>Now My question is when client program looks ejb bean using method 1 and method 2 then its returning bean but program is not able to lookup bean by method 3. Whats wrong with this method. can someone help me?
  Please see the below image as well which will tell you more about env.</p>
  
  <p><a href="https://i.stack.imgur.com/lZT8N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lZT8N.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/SVqQm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SVqQm.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/IESxC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IESxC.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/kskbX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kskbX.png" alt="enter image description here"></a></p>