I've got a problem with entity mapping.
Here is JBoss containing several modules, one of them contains package with entity mappings annotated with
@Entity
@Table(name = "PG_ATTR_A")
public class PgAttrA
// declaration omitted
}
In separate package and separate EJB module I have a DAO to access this data
@Stateless
@Clustered
public class PgAttrDao implements PgAttrDaoLocal, PgAttrDaoRemote {
@PersistenceContext (unitName = "Persistence_Unit")
EntityManager entityManager;
public List<PgAttrA> find(...) {
Query query = entityManager.createQuery("FROM PgAttrA WHERE ..skiped..");
// set some parameters, skipped
return query.getResultList();
}
}
Content of persistence.xml http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="Persistence_Unit" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>DS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
<property name="hibernate.cache.use_second_level_cache" value="false"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
</properties>
</persistence-unit>
The problem is DAO seems to don't know about ORM declared in PgAttr class.
I've got this particular exception:
Exception occurred in target VM: org.hibernate.hql.ast.QuerySyntaxException: PgAttrA is not mapped [FROM PgAttrA WHERE ..skiped..] java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: PgAttrA is not mapped [FROM PgAttrA WHERE ..skiped..]
I have some other DAO accessing this particular entity in the same module as the entity itself and it works like a charm. I just do not have access to sources of that DAO to add some new features.
So the question is why my DAO doesn't see the mapping and what should I do to fix it?
As a matter of fact I've just missed jar-file declaration in persistence.xml
so I've added
<jar-file>../jar_where_persistence_declared.jar</jar-file>
just after
<jta-data-source>DS</jta-data-source>
and problem has gone