title: Testing EJB 3.1 with JUnit gets error Invalid resource
body: <p>I am trying to test an Stateless bean with JUnit in netbeans. This bean uses an EntityManager.</p>
  
  <pre><code>@Stateless
  public class myEjb{
      @PersistenceContext
      private EntityManager em;
  
      public MyResult getResult(){
          return em.find(...);
      }
  }
  </code></pre>
  
  <p>Then I write a test class.</p>
  
  <pre><code>public class myTest{
      private static EJBContainer ec;
      private static Context ctx;
  
      @BeforeClass
      public static void setUpClass(){
          ec = EJBContainer.createEJBContainer();
          ctx = ec.getContext();
      }
      ....
  }
  </code></pre>
  
  <p>When I run the test, it does not work. I obtain the following message:
  Invalid resource : mydb__pm
  The error occurs when this line is executed:</p>
  
  <pre><code>ec = EJBContainer.createEJBContainer();
  </code></pre>
  
  <p>If a change my bean by removing the entity manager, it works. So, it seems that I have a problem with the entity manager.
  My persistence.xml file is simple:</p>
  
  <pre><code>&lt;persistence version="2.0" ...&gt;
    &lt;persistence-unit name="MetisDemoPU" transaction-type="JTA"&gt;
      &lt;jta-data-source&gt;MyDb&lt;/jta-data-source&gt;
      &lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
      &lt;properties/&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Finally, I create a JSF managed bean that called my EJB (which uses the entity manager) and it works.</p>
  
  <pre><code>@ManagedBean
  @RequestScoped
  public class myManagedBean{
      @EJB
      private OfferEjb offerEjb;
  
      ...
  }
  </code></pre>
  
  <p>Any help would be appreciated!</p>