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>

Answers


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).


Need Your Help

Ensure Vaadin load latest data in when clicking added components (such as TabSheet or Tree ...)

java vaadin vaadin7 vaadin4spring

When I add components to Vaadin's component (such as TabSheet or Tree) , the added components are cached. When user clicks the tab (or tree nodes) , if it contains db data , it shows stale data , not

Name of a function returning a generator

python naming-conventions

How do you name a function that returns a generator (that is, uses yield foo instead of return foo)?