title: On JBoss AS 7.1.1, why does Hibernate's AnnotationBinder not detect annotated entities?
body: <p>I'm trying to migrate a Spring application from JBoss AS 4.0.5.GA to 7.1.1.Final. In my <code>jboss-spring.xml</code> there is one bean, <code>engine</code>, whose init method results in the <code>createQuery</code> row below being executed.</p>
  
  <pre><code>public class QueueConfigurationDAO {
      private EntityManager _entityManager;
  
      @PersistenceContext
      public void setEntityManager(EntityManager entityManager) {
          _entityManager = entityManager;
      }
  
      public List&lt;QueueConfiguration&gt; getQueueConfigurations() {
          Query query = _entityManager.createQuery("from QueueConfiguration");
          return query.getResultList();
      }
  }
  </code></pre>
  
  <p>This results in the following stacktrace:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'engine' defined in "/C:/Users/Emil/JBoss/jboss-as-7.1.1.Final/standal
  one/deployments/zz10-wf.spring/META-INF/jboss-spring.xml": Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.i
  nternal.ast.QuerySyntaxException: QueueConfiguration is not mapped [from QueueConfiguration]
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1488)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
          at org.jboss.spring.factory.NamedXmlApplicationContext.&lt;init&gt;(NamedXmlApplicationContext.java:69)
          at org.jboss.spring.factory.NamedXmlApplicationContext.&lt;init&gt;(NamedXmlApplicationContext.java:59)
          at org.jboss.spring.deployers.as7.SpringBootstrapProcessor.deploy(SpringBootstrapProcessor.java:69)
          at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
          ... 5 more
  Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: QueueConfiguration is not mapped [from QueueConfiguration]
          at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1348)
          at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1289)
          at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:288)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_02]
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_02]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_02]
          at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_02]
          at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:241)
          at $Proxy118.createQuery(Unknown Source)        at se.sunstone.workflow.queues.QueueConfigurationDAO.getQueueConfigurations(QueueConfigurationDAO.java:28)
          at se.sunstone.workflow.queues.StandardQueueManager.configure(StandardQueueManager.java:71)
          at se.sunstone.workflow.queues.StandardQueueManager.start(StandardQueueManager.java:52)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_02]
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_02]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_02]
          at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_02]
          at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
          at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
          at $Proxy121.start(Unknown Source)      at se.sunstone.workflow.engine.ExecutionEngine.start(ExecutionEngine.java:177)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_02]
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_02]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_02]
          at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_02]
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1614)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1555)
          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485)
          ... 18 more
  Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: QueueConfiguration is not mapped [from QueueConfiguration]
          at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
          at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
          at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)
          at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:326)
          at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3252)
          at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3141)
          at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:694)
          at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:550)
          at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287)
          at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235)
          at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248)
          at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
          at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
          at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:101)
          at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:80)
          at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119)
          at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:214)
          at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:192)
          at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1537)
          at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:285)
          ... 48 more
  </code></pre>
  
  <p>I suppose that <code>QuerySyntaxException: QueueConfiguration is not mapped</code> means that my</p>
  
  <pre><code>@javax.persistence.Entity
  @javax.persistence.Table(name = "queue_configuration")
  public class QueueConfiguration { /* ... */ }
  </code></pre>
  
  <p>class is not recognized as an entity by Hibernate. Indeed, when I run the application in JBoss 4, the startup logs contain rows like</p>
  
  <pre><code>INFO  [org.hibernate.cfg.AnnotationBinder] Binding entity from annotated class: se.sunstone.workflow.queues.QueueConfiguration
  </code></pre>
  
  <p>but no such rows appear in the log when I try to deploy it in JBoss 7. If I comment out the <code>engine</code> bean from <code>jboss-spring.xml</code>, the application happily deploys without exceptions.</p>
  
  <p>I'm using JBoss 7's built-in Hibernate module and I'm deploying my webapp using the Snowdrop module. I have monkeyed around with this for a few days now, including trying to use Hibernate 3 instead, but the problem persists.</p>
  
  <p>If I explicitly specify <code>&lt;class&gt;se.sunstone.workflow.queues.QueueConfiguration&lt;/class&gt;</code> in <code>persistence.xml</code>, the application deploys and the logs now contain the same AnnotationBinder rows as when running on JBoss 4. However, the application also has a bunch of other annotated entities, whose DAOs are omitted from the configs below, and they are not detected unless I specify them too in <code>persistence.xml</code>. Apparently the AnnotationBinder does not detect my annotated entities unless I specify them in <code>persistence.xml</code>. Why is that?</p>
  
  <h2>Details</h2>
  
  <p>Archive layout:</p>
  
  <pre><code>zz10-wf.spring
  -- META-INF
  ---- jboss-deployment-structure.xml
  ---- jboss-spring.xml
  ---- jpa-persistence.xml
  ---- MANIFEST-MF
  -- (Java package hierarchy)
  </code></pre>
  
  <p>Following <a href="https://docs.jboss.org/author/display/AS7/Spring+applications+development+and+migration+guide#Springapplicationsdevelopmentandmigrationguide-UsingSpringmanagedpersistenceunits" rel="nofollow">these instructions</a> I have renamed the traditional <code>persistence.xml</code> to <code>jpa-persistence.xml</code> so that JBoss will not detect it and launch its own Hibernate instance.</p>
  
  <p><code>zz10-wf.spring</code> is currently deployed as an exploded directory, but the same thing happens if I deploy it as an uncompressed zip archive.</p>
  
  <p><code>jboss-deployment-structure.xml</code>:</p>
  
  <pre><code>&lt;jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"&gt;
      &lt;deployment&gt;
          &lt;exclusions&gt;
              &lt;module name="org.hibernate"/&gt;
          &lt;/exclusions&gt;
      &lt;/deployment&gt;
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p><code>jboss-spring.xml</code>:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:jee="http://www.springframework.org/schema/jee"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
                               http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                             http://www.springframework.org/schema/jee
                               http://www.springframework.org/schema/jee/spring-jee-2.0.xsd
                             http://www.springframework.org/schema/tx
                               http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
    &lt;!-- =========  Central application configuration  ========= --&gt;
    &lt;bean id="queueManager" class="se.sunstone.workflow.queues.StandardQueueManager"&gt; 
      &lt;property name="queueConfigurationDAO" ref="queueConfigurationDAO"/&gt;
    &lt;/bean&gt;
  
    &lt;bean id="engine" class="se.sunstone.workflow.engine.ExecutionEngine" init-method="start" destroy-method="stop"&gt;  
      &lt;property name="queueManager" ref="queueManager"/&gt;
    &lt;/bean&gt;
  
    &lt;!-- =========  DAOs  ========= --&gt;
    &lt;bean id="queueConfigurationDAO" class="se.sunstone.workflow.queues.QueueConfigurationDAO" /&gt; 
  
    &lt;!-- =========  JPA  ========= --&gt;
    &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;
  
    &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceXmlLocation" value="classpath*:META-INF/jpa-persistence.xml"/&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;property name="persistenceUnitName" value="workflow" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
        &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
          &lt;property name="showSql" value="false" /&gt;
          &lt;property name="generateDdl" value="true" /&gt;
          &lt;property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
        &lt;/bean&gt;
      &lt;/property&gt;
    &lt;/bean&gt;
  
    &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
    &lt;/bean&gt;
  
    &lt;tx:annotation-driven /&gt;
  
    &lt;jee:jndi-lookup id="dataSource" jndi-name="java:jboss/WorkflowDS"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><code>jpa-persistence.xml</code>:</p>
  
  <pre><code>&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="workflow"&gt;
        &lt;!-- &lt;class&gt;se.sunstone.workflow.queues.QueueConfiguration&lt;/class&gt; --&gt;
    &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>I have tried moving configuration details back and forth between <code>jpa-persistence.xml</code> and the <code>entityManagerFactory</code> bean definition, the results are largely the same and the application agrees to run with this minimal <code>jpa-persistence.xml</code> as long as the <code>QueueConfiguration</code> row above is uncommented.</p>