title: javax.naming.NameNotFoundException: MyBean#MyBean not found
body: <p>I have a multi module maven project which contains a jar module (models), two EJB modules (repository, service) and a web module.
  The first thing that may cause the problem is that I don't know in which EJB module should I place the persistence.xml file. </p>
  
  <p>It looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"&gt;
  
     &lt;persistence-unit name="jthrdb"&gt;
  
          &lt;jta-data-source&gt;MySQL&lt;/jta-data-source&gt;
  
     &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I've also tried placing it in both repository and service modules (src/main/resources/META-INF) but I'm still getting this exception:</p>
  
  <pre><code>javax.naming.NameNotFoundException: MyBean#MyBean not found
  at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237)
  at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204)
  at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66)
  at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:114)
  at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:478)
  at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
  at javax.naming.InitialContext.lookup(InitialContext.java:411)
  at javax.naming.InitialContext.lookup(InitialContext.java:411)
  at com.sun.ejb.EjbNamingReferenceManagerImpl.resolveEjbReference(EjbNamingReferenceManagerImpl.java:183)
  at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbReferenceProxy.create(ComponentEnvManagerImpl.java:1143)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:745)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:715)
  at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:159)
  at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:471)
  at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
  at javax.naming.InitialContext.lookup(InitialContext.java:411)
  at javax.naming.InitialContext.lookup(InitialContext.java:411)
  at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:613)
  at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:484)
  at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:141)
  at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:127)
  at com.sun.enterprise.container.common.impl.util.InjectionManagerImpl.createManagedObject(InjectionManagerImpl.java:324)
  at com.sun.enterprise.web.WebContainer.createServletInstance(WebContainer.java:983)
  at com.sun.enterprise.web.WebModule.createServletInstance(WebModule.java:2130)
  at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1404)
  at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1211)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:237)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
  at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
  at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
  at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
  at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
  at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
  at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
  at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
  at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
  at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
  at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
  at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
  at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
  at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here's a part of the servlet:</p>
  
  <pre><code>@WebServlet("/MyServlet")
  public class MyServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  @EJB
  private CandidateBean bean;
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public MyServlet() {
      super();
      // TODO Auto-generated constructor stub
  }
  
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
   *      response)
   */
  @Override
  protected void doGet(HttpServletRequest request,
          HttpServletResponse response) throws ServletException, IOException {
      PrintWriter out = response.getWriter();
      Candidate temp = new Candidate();
      temp.setFirstName("Pos");
      // bean.insert(temp);
      out.println("&lt;html&gt;");
      out.println("&lt;body&gt;");
      out.println("&lt;h1&gt;" + bean.saySomething() + "&lt;/h1&gt;");
      out.println("&lt;/body&gt;");
      out.println("&lt;/html&gt;");
  }
  }
  </code></pre>