title: Issue with EJB - Stateful Session Bean and Servlet
body: <p>I have a servlet code which calls a ejb stateful session bean code as follows,   </p>
  
  <pre><code>public class UsesBeansSF extends HttpServlet {   
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try {
            // do something
         }
  
      finally {}
   } 
  
  private SessionBeanSFRemote lookupSessionBeanSFRemote() {
      try {
          Context c = new InitialContext();
          return (SessionBeanSFRemote) c.lookup("java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote");
      } catch (NamingException ne) {
          Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
          throw new RuntimeException(ne);
      }
  }
  
  }
  </code></pre>
  
  <p>This code works well without the line between * marks. However, when I am adding <strong>SessionBeanSFRemote sessionBeanSF = lookupSessionBeanSFRemote()</strong> this line (means calling a Stateful Session Bean), the code is giving error. Actually, I have to call the stateless session bean in order to perform some job. Can anybody help me why it is happening ? Thanks in advance.</p>
  
  <p>Error message is following:</p>
  
  <p><strong>type Exception report message</strong></p>
  
  <pre><code>descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
  </code></pre>
  
  <p><strong>exception</strong></p>
  
  <pre><code>javax.servlet.ServletException: PWC1392: Error instantiating servlet class websSF.comsSF.UsesBeansSF
  </code></pre>
  
  <p><strong>root cause</strong></p>
  
  <pre><code>com.sun.enterprise.container.common.spi.util.InjectionException: 
           Error creating managed object for class websSF.comsSF.UsesBeansSF
  </code></pre>
  
  <p><strong>root cause</strong></p>
  
  <pre><code>java.lang.reflect.InvocationTargetException
  </code></pre>
  
  <p><strong>root cause</strong></p>
  
  <pre><code>java.lang.RuntimeException: javax.naming.NamingException: 
  Lookup failed for 'java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote' in SerialContext  
  [Root exception is javax.naming.NamingException: 
  ejb ref resolution error for remote business interfaceejbSF.SessionBeanSFRemote [Root exception is java.lang.NullPointerException]]
  </code></pre>
  
  <p><strong>root cause</strong></p>
  
  <pre><code>javax.naming.NamingException: 
  Lookup failed for 'java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote' in SerialContext  
  [Root exception is javax.naming.NamingException: 
  ejb ref resolution error for remote business interfaceejbSF.SessionBeanSFRemote
  [Root exception is java.lang.NullPointerException]]
  </code></pre>
  
  <p><strong>root cause</strong></p>
  
  <pre><code>javax.naming.NamingException: ejb ref resolution error for remote business 
  interfaceejbSF.SessionBeanSFRemote [Root exception is java.lang.NullPointerException]
  </code></pre>
  
  <p><strong>root cause</strong></p>
  
  <pre><code>java.lang.NullPointerException
  note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.
  </code></pre>
  
  <p>Server: <strong>GlassFish Server Open Source Edition 3.0.1</strong></p>