2

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?

user1455836
  • 752
  • 6
  • 18

2 Answers2

0

if you use JPQL change your query to:

 Query query = entityManager.createQuery("SELECT p FROM PgAttrA p WHERE ..skiped..");

JPQL queries example from here

If you use HQL :

Query query = entityManager.createQuery("FROM PgAttrA AS p WHERE ..skiped..");

HQLQueries example from here

if your problem is not solved inspect your persistence.xml,

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • @user1455836 why you use `org.hibernate.ejb.HibernatePersistence` you can use `org.eclipse.persistence.jpa.PersistenceProvider` it is easier –  Oct 02 '13 at 10:15
  • this declaration is used throughout the server so I'll better stick with it Meanwhile, thank you for idea of inspecting persistence.xml, I've managed to find answer due to it. – user1455836 Oct 02 '13 at 10:25
  • @user1455836 I edited my answer you can upvote it or accept it to help other users –  Oct 02 '13 at 10:56
0

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

user1455836
  • 752
  • 6
  • 18