I have the following structure of a web application (war) running on JBoss EAP 6.1 with JPA 2 and Hibernate 4.2:
- Entity.jar (from other internal project)
- Application.war (containing the Entity.jar in WEB-INF/lib, included as maven dependency, not as maven module)
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.
If I call the method of the EJB containing the query, I got the error:
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]
My entity User from Entity.jar looks like:
@Entity
@Table(name = "PL1_USER")
public class User implements Serializable {
...
EJB from Application.war:
@Stateless
public class UserService {
@PersistenceContext(unitName = "my-unit")
private EntityManager entityManager;
public User getUser(String username) {
TypedQuery<User> query = entityManager.createQuery("SELECT u FROM User as u WHERE u.name = :name", User.class);
query.setParameter("name", username);
return query.getSingleResult();
}
}
persistence.xml from Application.war (WEB-INF/classes/META-INF):
<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">
<persistence-unit name="my-unit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasource/MY-DS</jta-data-source>
<jar-file>Entity.jar</jar-file>
<properties>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="false" />
<property name="hibernate.jdbc.batch_size" value="30" />
<property name="hibernate.jdbc.fetch_size" value="100" />
<property name="hibernate.max_fetch_depth" value="0" />
<property name="hibernate.order_updates" value="true" />
<property name="hibernate.use_identifier_rollback" value="true" />
<!-- JDBC Driver returns row count for batch statements -->
<property name="hibernate.jdbc.batch_versioned_data" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
</properties>
</persistence-unit>
Structure of Application.war:
- 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
If you need more information/details please let me know.
I already searched on google, but nothing that I found worked for me.
I'm very happy if anyone can help me.