title: Can't get persistence to work in JBoss AS 7 ("Can't find a deployment unit named at subdeployment")
body: <p>I try to implement a demo that uses JBoss AS 7 with default hibernate and default Database shipped with JBoss AS. My implementation is similar to the "login" example from JBoss (I have some extra projects to implement a web service and deploy as EAR) and I can't catch the difference. Anyway I constantly get Runtime Exceptions such as </p>
  
  <pre><code>Caused by: java.lang.RuntimeException: Can't find a deployment unit named  at subdeployment "myproject.persistence.war" of deployment "myproject.ear"
      at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:94) [jboss-as-weld-7.0.2.Final.jar:7.0.2.Final]
      at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.resolvePersistenceContext(WeldJpaInjectionServices.java:59) [jboss-as-weld-7.0.2.Final.jar:7.0.2.Final]
      at org.jboss.weld.util.Beans.injectEEFields(Beans.java:784) [weld-core-1.1.2.Final.jar:2011-07-26 15:02]
  </code></pre>
  
  <p>My MANIFEST.MF</p>
  
  <pre><code>Manifest-Version: 1.0
  Dependencies: org.hibernate
  </code></pre>
  
  <p>My beans.xml is empty. In my lib folder I have the hibernate jars to have access to native hibernate features.</p>
  
  <p>My persistence.xml</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_2_0.xsd"
      version="2.0"&gt;
      &lt;persistence-unit name="accessControlDatabase"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;jta-data-source&gt;java:jboss/datasources/ExampleDS&lt;/jta-data-source&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;  
  </code></pre>
  
  <p>And my two relevant classes:</p>
  
  <pre><code>import javax.enterprise.inject.Produces;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  
  public class Resources {
      @SuppressWarnings("unused")
      @Produces
      @PersistenceContext(name = "accessControlDatabase")
      private EntityManager em;
  }
  
  import java.util.List;
  
  import javax.enterprise.context.RequestScoped;
  import javax.inject.Inject;
  import javax.inject.Named;
  import javax.persistence.EntityManager;
  
  import myproject.model.Session;
  import myproject.model.User;
  
  @Named("accessControlRepository")
  @RequestScoped
  public class AccessControlRepository {
      @Inject
      private EntityManager em;
  
      @SuppressWarnings("unchecked")
      public List&lt;Session&gt; getAllSessions() {
          return em.createQuery("from Session").getResultList();
      }
  }
  </code></pre>
  
  <p>What can cause the exception? What should I look for to resolve the problem?</p>