title: Spring/Hibernate fails to initialize the EntityManager when using mix of annotations and hbm for entities
body: <p>I have a Spring/Hibernate project with entities defined using both hbm's and annotations.</p>
  
  <p>When I am trying to deploy the project I get the following error message: </p>
  
  <pre><code>Caused by: org.hibernate.MappingException: Following super classes referenced in extends not found: hibernate.examples.model.Task
      at org.hibernate.cfg.Configuration.processExtendsQueue(Configuration.java:1768) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1690) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
      ....................
  </code></pre>
  
  <p>The reason I have to keep using both is because some of the code is legacy and I cannot touch that at the moment. And we have to start using the annotations for creating any new entities moving forward. </p>
  
  <p>This is how I am registering both kinds of mappings into the configuration: </p>
  
  <pre><code>    @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
          final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
          em.setDataSource(dataSource());
          em.setPackagesToScan("hibernate.examples.model", "models");
          em.setMappingResources("Task.hbm.xml");
          em.setMappingResources("HealthTask.hbm.xml");
  
          final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
          em.setJpaVendorAdapter(vendorAdapter);
          em.setJpaProperties(hibernateProperties());
          return em;
      }
  </code></pre>
  
  <p>The <code>setPackagesToScan</code> method scans for all the entities marked by annotations and <code>setMappingResources</code> is supposed to take care of the hbm files. </p>
  
  <p>When I comment out the <code>em.setMappingResources.....</code> then the project gets deployed without any issues. </p>
  
  <p>Also, the weird part to note is that when I run it as a standalone application i.e. using <code>public static void main(String[] args)</code> I do not have any issues working with both kinds of mapping. All the entities get registered and schema gets created. </p>
  
  <p>Here is how I run the project: </p>
  
  <pre><code>public class ConceptRunner {
  
      public static void main(String[] args) {
          AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  
          ctx.register(HibernateConfiguration.class);
          ctx.refresh();
  
          System.exit(0);
  
      }
  
  }
  </code></pre>
  
  <p>But as soon as I deploy the project, it fails to register the hbm files.</p>
  
  <p>Here are my hbm files: </p>
  
  <p>Task.hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="hibernate.examples.model.Task" table="TASKS" abstract="true"&gt;
          &lt;id name="id" type="java.lang.Long"&gt;
              &lt;column name="ID" precision="22" scale="0"/&gt;
              &lt;generator class="identity"/&gt;
          &lt;/id&gt;
          &lt;discriminator column="TYPE" type="string"/&gt;
          &lt;property name="type" type="java.lang.String" insert="false" update="false"&gt;
              &lt;column name="TYPE" length="10"/&gt;
          &lt;/property&gt;
          &lt;property name="name" type="java.lang.String"&gt;
              &lt;column name="NAME" length="50"/&gt;
          &lt;/property&gt;
          &lt;property name="description" type="java.lang.String"&gt;
              &lt;column name="DESCRIPTION" length="250"/&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>HealthTask.hbm.xml</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;subclass name="hibernate.examples.model.HealthTask"
                extends="hibernate.examples.model.Task" discriminator-value="HEALTH"&gt;
          &lt;property name="requestServed" type="java.lang.Long"&gt;
              &lt;column name="REQUEST_SERVED"/&gt;
          &lt;/property&gt;
          &lt;property name="requestFailed" type="java.lang.Long"&gt;
              &lt;column name="REQUEST_FAILED"/&gt;
          &lt;/property&gt;
          &lt;property name="totalRequest" type="java.lang.Long"&gt;
              &lt;column name="TOTAL_REQUEST"/&gt;
          &lt;/property&gt;
      &lt;/subclass&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Please let me know if there is any other information that you would like from me.. </p>