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:
java.lang.IllegalArgumentException: Unknown entity: MyClassHere
Caused by: org.hibernate.MappingException: Unknown entity: MyClassHere
This occurs in the EntityManager.merge call.
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.
I tried adding the following to persistence.xml
<exclude-unlisted-classes>false</exclude-unlisted-classes>
In hibernate.cfg.xml I added:
<property name="packagesToScan">myNamespace.*</property>
Then:
<property name="packagesToScan">
<array>
<value>myNamespace.*</value>
</array>
</property>
That gave me an error that content of "property" must match null. Then I tried:
<mapping class="myNamespace.*" />
What am I missing?
Edit: 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.