title: How should be EJB Stateless Session Bean correctly injected into the web module?
body: <p>Being completely new to Java EE (but not to Java itself) I'm trying to build a very simple "Enterprise Application" with Hibernate as JPA provider and JSF as the actual UI framework. For this purposes I'm using the NetBeans 7 with GlassFish 3.1.</p>
  
  <p><strong>{ApplicationName}-ejb:</strong></p>
  
  <p>I've accomplished to generate <strong>entity classes</strong> from database and <strong>local sesssion beans</strong> for these entities. <strong>Beans.xml</strong> is in place.</p>
  
  <pre><code>@Stateless
  public class QuestFacade extends AbstractFacade&lt;Quest&gt; implements QuestFacadeLocal {
      // some methods here as well as EntityManager injection ...
  }
  </code></pre>
  
  <p><strong>{ApplicationName}-war:</strong></p>
  
  <p>I've created a simple POJO as a backing bean for the JSF page. I've annotated it with <code>javax.inject.@Named</code> and <code>javax.enterprise.context.@SessionScoped</code>. This backing bean is now accessible from the JSF page as well as being injected when the actual page is accessed. <strong>Beans.xml</strong> is in place as well.</p>
  
  <pre><code>@Named
  @SessionScoped
  public class QuestBean implements Serializable {
  
      @EJB
      protected QuestFacade questFacade;
  
      // several methods delegating lookups to the questFacade ...
  }
  </code></pre>
  
  <p>Having this deployed and page accessed, I'm, however, getting an error from GlassFish that the <code>QuestFacade</code> cannot be looked up by the JNDI.</p>
  
  <p>The stacktrace is quite long but the initial cause could be enough:</p>
  
  <pre><code>Caused by: javax.naming.NamingException: Lookup failed for 'model.session.QuestFacade#model.session.QuestFacade' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: model.session.QuestFacade#model.session.QuestFacade not found]
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:173)
      ... 74 more
  Caused by: javax.naming.NameNotFoundException: model.session.QuestFacade#model.session.QuestFacade not found
      at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:248)
      at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:215)
      at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
      at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:119)
      at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:505)
      ... 78 more
  </code></pre>
  
  <p>I understand that I'm persuading GlassFish to inject an EJB from a different module within the same application. Should the <code>@Remote</code> interface be used instead? I've also tried to explicitely specify the name for both <code>@Stateless</code> and <code>@EJB</code> annotation but without any success.</p>
  
  <p>I believe that I'm doing something fundamentaly wrong, but I cannot find out what.</p>
  
  <p>Any suggestion or would be greatly appreciated!</p>