title: How to configure hibernate to scan for entities in a different module
body: <p>I have module A and module B which both have JPA annotated classes. Module B has an unit test that pulls in a couple of those entities from A. 
  Both modules compile fine, the runtime dependencies are set OK, but I get the following error when I try to run the unit test:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Unknown entity: MyClassHere
  Caused by: org.hibernate.MappingException: Unknown entity: MyClassHere
  </code></pre>
  
  <p>This occurs in the EntityManager.merge call.</p>
  
  <p>Since module B has all the hibernate config files etc, I'm guessing it's simply not picking up that my class from A is an entity.</p>
  
  <p>I tried adding the following to persistence.xml</p>
  
  <pre><code>&lt;exclude-unlisted-classes&gt;false&lt;/exclude-unlisted-classes&gt;
  </code></pre>
  
  <p>In hibernate.cfg.xml I added:</p>
  
  <pre><code>&lt;property name="packagesToScan"&gt;myNamespace.*&lt;/property&gt;
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code> &lt;property name="packagesToScan"&gt;
                  &lt;array&gt;
                      &lt;value&gt;myNamespace.*&lt;/value&gt;
                  &lt;/array&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p>That gave me an error that content of "property" must match null.
  Then I tried:</p>
  
  <pre><code>&lt;mapping class="myNamespace.*" /&gt;
  </code></pre>
  
  <p>What am I missing? </p>
  
  <p><strong>Edit:</strong> One thing that I forgot to mention that might be of significance is that the two modules are set up as separate projects (I'm using eclipse) so the directory structure is different. The run time dependencies are all set up correctly but since the .class files end up in different directories, I think hibernate might not be scanning those.</p>