title: using Spring's persistenceXmlLocation without <class> in persistence.xml
body: <h2>My question:</h2>
  
  <p>Is there a way to tell Spring/JPA to automatically detect classes annotated with @Entity?</p>
  
  <h2>Background:</h2>
  
  <p>This is my configuration of the entityManagerFactory</p>
  
  <pre><code>&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>... and this is my persistence.xml ...</p>
  
  <pre><code>&lt;persistence-unit name="foo"&gt;
    &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
    &lt;properties&gt;
      &lt;property name="hibernate..." value="..."/&gt;
      &lt;property ...
    &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>This configuration is working. But: When I add the following line to my entityManagerFactory configuration</p>
  
  <pre><code>&lt;property name="persistenceXmlLocation" value="META-INF/persistence.xml" /&gt;
  </code></pre>
  
  <p>JPA doesn't find my classes annotated with @Entity. So, I get Exceptions like this one:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Unknown entity: foo.Bar
  </code></pre>
  
  <p>where foo.Bar is a class annotated with @javax.persistence.Entity</p>
  
  <p>When I now add</p>
  
  <pre><code>&lt;class&gt;foo.Bar&lt;/class&gt;
  </code></pre>
  
  <p>to my persistence.xml, everything's fine again. But why do I have to specify my classes in persistence.xml when using persistenceXmlLocation and otherwise not?</p>
  
  <p>Note: You might ask why I want to use persistenceXmlLocation: It would solve <a href="https://stackoverflow.com/questions/385532/how-to-configure-jpa-for-testing-in-maven">this problem</a>.</p>