title: JPA entities from external jar not found in war
body: <p>I have the following structure of a web application (war) running on JBoss EAP 6.1 with JPA 2 and Hibernate 4.2:</p>
  
  <ul>
  <li>Entity.jar (from other internal project)</li>
  <li>Application.war (containing the Entity.jar in WEB-INF/lib, included as maven dependency, not as maven module)</li>
  </ul>
  
  <p>In my web application project (Application.war) I have an EJB containing an EntityManager. In the EJB I would like to create a JQL-Query (em.createQuery) for an Entity from Entity.jar.</p>
  
  <p>If I call the method of the EJB containing the query, I got the error:</p>
  
  <pre><code>Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [SELECT u FROM User as u WHERE u.name = :name]
  </code></pre>
  
  <p>My entity User from Entity.jar looks like:</p>
  
  <pre><code>@Entity
  @Table(name = "PL1_USER")
  public class User implements Serializable {
  ...
  </code></pre>
  
  <p>EJB from Application.war:</p>
  
  <pre><code>@Stateless
  public class UserService {
  
  @PersistenceContext(unitName = "my-unit")
  private EntityManager entityManager;
  
  public User getUser(String username) {
      TypedQuery&lt;User&gt; query = entityManager.createQuery("SELECT u FROM User as u WHERE u.name = :name", User.class);
      query.setParameter("name", username);
      return query.getSingleResult();
  }
  }
  </code></pre>
  
  <p>persistence.xml from Application.war (WEB-INF/classes/META-INF):</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0"&gt;
  
  &lt;persistence-unit name="my-unit" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;jta-data-source&gt;java:jboss/datasource/MY-DS&lt;/jta-data-source&gt;
  
      &lt;jar-file&gt;Entity.jar&lt;/jar-file&gt;
  
      &lt;properties&gt;
          &lt;property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /&gt;
          &lt;property name="hibernate.archive.autodetection" value="class, hbm" /&gt;
          &lt;property name="hibernate.show_sql" value="false" /&gt;
          &lt;property name="hibernate.format_sql" value="true" /&gt;
          &lt;property name="hibernate.use_sql_comments" value="false" /&gt;
          &lt;property name="hibernate.jdbc.batch_size" value="30" /&gt;
          &lt;property name="hibernate.jdbc.fetch_size" value="100" /&gt;
          &lt;property name="hibernate.max_fetch_depth" value="0" /&gt;
          &lt;property name="hibernate.order_updates" value="true" /&gt;
          &lt;property name="hibernate.use_identifier_rollback" value="true" /&gt;
  
          &lt;!-- JDBC Driver returns row count for batch statements --&gt;
          &lt;property name="hibernate.jdbc.batch_versioned_data" value="true" /&gt;
  
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" /&gt;
  
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p></p>
  
  <p>Structure of Application.war:</p>
  
  <pre><code>- Application.war
      - META-INF
          - MANIFEST.MF (containing Entity.jar in Class-Path)
      - resources
      - WEB-INF
          - com
              - example
                  - UserService.class
          - classes
              - META-INF
                  - persistence.xml
          - lib
              - Entity.jar
      - index.xhtml
  </code></pre>
  
  <p>If you need more information/details please let me know.</p>
  
  <p>I already searched on google, but nothing that I found worked for me.</p>
  
  <p>I'm very happy if anyone can help me.</p>