title: Lookup returns new instance of Stateful session bean
body: <p>I am using <code>Java EE 5</code>, <code>EJB 3.0</code>, <code>Jboss AS 4.3.2</code>.<br>
  I have simplest <code>Stateful</code> bean  </p>
  
  <pre><code>@Local
  public interface IStateBean 
  {
  }
  @Stateful
  public class StateBean implements IStateBean
  {  
     private static int number = 0;
  
     @PostConstruct
     void init()
     {
        number++;
        System.out.println("@PostConstruct: " + number);
     }
  
     @PreDestroy
     void destroy()
     {
        number--;
        System.out.println("@PreDestroy: " + number);  
     }
  }
  </code></pre>
  
  <p>I do lookup in servlet for this bean  </p>
  
  <pre><code>public class MyServlet extends HttpServlet
  {  
     @Override
     public void doGet(final HttpServletRequest aRequest, final HttpServletResponse aResponse) throws ServletException, IOException
     {  
        IStateBean bean = new InitialContext().lookup("app-ear/StateBean/local");
        // ...
     }
  }  
  </code></pre>
  
  <p>But each time new instance of <code>StateBean</code> is created.<br>
  I can call <code>lookup</code> twice but new instance of <code>StateBean</code> is created again  </p>
  
  <pre><code>   @Override
     public void doGet(final HttpServletRequest aRequest, final HttpServletResponse aResponse) throws ServletException, IOException
     {  
        IStateBean bean1 = new InitialContext().lookup("app-ear/StateBean/local"); 
        IStateBean bean2 = new InitialContext().lookup("app-ear/StateBean/local"); // new instance is created
        // ...
     }  
  </code></pre>
  
  <p><strong>I expect the same instance in the same http-session</strong>  </p>
  
  <p>Servlet mapping in web.xml  </p>
  
  <pre><code>   &lt;servlet&gt;
        &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;com.package.MyServlet&lt;/servlet-class&gt;
     &lt;/servlet&gt;  
     &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
  </code></pre>