title: Persistence unit not finding managed entity
body: <p><code>@PersistenceContext</code> entity manager cannot find an/any entity class which it appeared to have processed during container launch.</p>
  
  <p>During persistence unit setup, it appears that the container finds and registers the entity:</p>
  
  <pre><code>2012-05-17 15:28:21,978 INFO  [org.hibernate.cfg.annotations.Version] (main) Hibernate Annotations 3.4.0.GA
  2012-05-17 15:28:21,997 INFO  [org.hibernate.annotations.common.Version] (main) Hibernate Commons Annotations 3.1.0.GA
  2012-05-17 15:28:22,004 INFO  [org.hibernate.ejb.Version] (main) Hibernate EntityManager 3.4.0.GA
  2012-05-17 15:28:22,039 INFO  [org.hibernate.ejb.Ejb3Configuration] (main) Processing 
  PersistenceUnitInfo [
      name: dashboardPu
      ...]
  2012-05-17 15:28:22,069 WARN  [org.hibernate.ejb.Ejb3Configuration] (main) Persistence provider caller does not implement the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
  2012-05-17 15:28:22,146 INFO  [org.hibernate.cfg.AnnotationBinder] (main) Binding entity from annotated class: scholastic.dashboard.dto.ReportRequest
  2012-05-17 15:28:22,161 INFO  [org.hibernate.cfg.annotations.QueryBinder] (main) Binding Named query: ReportRequest.getReportsByUser =&gt; from ReportRequest where userId = :userId
  </code></pre>
  
  <p>However, the later attempt to use that entity fails. I've verified that the entitymanager is indeed using dashboardPu (there are 3 persistence units in this ear) by dropping into the debugger and looking through the entitymanager>factory>persistenceUnit.</p>
  
  <pre><code>2012-05-17 15:28:54,730 DEBUG [org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter] (http-127.0.0.1-8080-2) Opening JPA EntityManager in OpenEntityManagerInViewFilter
  2012-05-17 15:28:54,731 DEBUG [org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter] (http-127.0.0.1-8080-1) Using EntityManagerFactory 'dashboardEntityManagerFactory' for OpenEntityManagerInViewFilter
  2012-05-17 15:28:54,731 DEBUG [org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter] (http-127.0.0.1-8080-1) Opening JPA EntityManager in OpenEntityManagerInViewFilter
  2012-05-17 15:28:54,775 DEBUG [scholastic.dashboard.dao.ReportRequestDao] (http-127.0.0.1-8080-2) Get reports for secretuserid
  2012-05-17 15:28:54,797 WARN  [org.hibernate.hql.QuerySplitter] (http-127.0.0.1-8080-2) no persistent classes found for query class: from scholastic.dashboard.dto.ReportRequest where user_id = secretuserid
  </code></pre>
  
  <p>I got here by first having it fail to find the <code>"ReportRequest.getReportsByUser"</code> query using <code>em.createNamedQuery()</code>, then trying a query w/o using the full path name to the entity class <code>from ReportRequest where userId = :userId</code>, and then the query in the last code block line above.</p>
  
  <p>Using JBoss 5.1, JPA 2, Hibernate 3.3 or 3.6, Spring 3.0.5.</p>
  
  <p>Code snippets:</p>
  
  <pre><code>@Entity
  @Table(name="td_report_request")
  @NamedQueries({
  @NamedQuery(name=ReportRequestDao.GET_REPORTS_BY_USER, 
          query="from ReportRequest where userId = :userId"),
  })
  public class ReportRequest extends SlmsGuidAbstract {...}
  
  ...
  @Repository
  public class ReportRequestDao {
  
      @PersistenceContext
      private EntityManager em;
  
      public List&lt;ReportRequest&gt; getReportRequests(String userId) {
      // TODO uncomment this line and remove the one after when we go to JBoss &gt;= 6
  //      TypedQuery&lt;ReportRequest&gt; query = em.createNamedQuery(GET_REPORTS_BY_USER, ReportRequest.class);
  //      Query query = em.createNamedQuery(GET_REPORTS_BY_USER);
      Query query = em.createQuery("from scholastic.dashboard.dto.ReportRequest where user_id = " + userId);
  
  ...
  &lt;bean id="dashboardEntityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
        &lt;property name="dataSource" ref="lycea.ds.jndi-MySqlDS" /&gt;
        &lt;property name="persistenceUnitName" value="dashboardPu"/&gt;
  &lt;/bean&gt;
  ...
  &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="dashboardPu" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;jta-data-source&gt;java:/MySqlDS&lt;/jta-data-source&gt;
      &lt;properties&gt;
          &lt;property name="jboss.entity.manager.factory.jndi.name" value="java:/dashboardPu"/&gt;
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
          &lt;property name="hibernate.query.factory_class" value="org.hibernate.hql.ast.ASTQueryTranslatorFactory"/&gt;
          &lt;property name="hibernate.connection.release_mode" value="auto"/&gt;
          &lt;property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>