Hibernate cannot find my Entity classes which are in a separate jar file
My persistence.xml is located in A.jar and entity classes are in B.jar. When trying to create a query using entity manager (from A.jar), I got exception saying it cannot find NamedQueries. However, named queries are listed on the entity class using annotation.
Tried to use <jar-file/> to include B.jar in persistence.xml, but it doesn't work. Here's what I've tried.
<persistence> <persistence-unit name="myapp"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/DefaultDS</jta-data-source> <properties> ... ... </properties> <jar-file>lib/B.jar</jar-file> <jar-file>../lib/B.jar</jar-file> <jar-file>WEB-INF/lib/B.jar</jar-file> <jar-file>B.jar</jar-file> <class>com.mypackage.Bar</class> <class>com.mypackage.Foo</class> </persistence-unit> </persistence>
Figured out my problem.
<jar-file/> is not necessary.
All the entity classes in jars other than current jar should be listed in <class/>, persistence.xml should be configured so the <class/> node is placed in front of <properties/> (XML schema defines all those nodes as sequence).