2

Using JPA 2.0, Java EE 5, Weblogic 10.3 (11g), JDK 6, EclipseLink.

When i attempt to run this:

 CriteriaQuery _criteriaquery = EM.getCriteriaBuilder().createQuery(Clazz);
        Query query = EM.createQuery(_criteriaquery);
        return query.getResultList();

I just get this :

Caused by: Exception [EclipseLink-6029] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.QueryException
    Exception Description: A reference class must be provided.
    Query: ReportQuery()
        at org.eclipse.persistence.exceptions.QueryException.referenceClassMissing(QueryException.java:1004)
        at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkDescriptor(ObjectLevelReadQuery.java:744)
        at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:661)

What could be the cause of this error ?

GabrielBB
  • 2,479
  • 1
  • 35
  • 49

3 Answers3

1

Your query isn't complited. You should add SELECT and FROM clauses.

CriteriaQuery<SomeEntity> _criteriaquery = EM.getCriteriaBuilder().createQuery(SomeEntity.class);
Root<SomeEntity> selector = _criteriaquery.from(SomeEntity.class); // FROM
_criteriaquery.select(selector);  // SELECT
Query query = EM.createQuery(_criteriaquery);
return query.getResultList();
Ilya
  • 29,135
  • 19
  • 110
  • 158
0

You should use

CriteriaQuery _criteriaquery = EM.getCriteriaBuilder().createQuery(Clazz.class);

instead of

CriteriaQuery _criteriaquery = EM.getCriteriaBuilder().createQuery(Clazz);
Donato Szilagyi
  • 4,279
  • 4
  • 36
  • 53
  • If the code compiles, then `Clazz` is a variable: `Class> Clazz = Object.class`. The correct would be to write it with lowercase, but it's not really wrong. – MiguelKVidal Aug 14 '17 at 02:48
0

The same exception can also be thrown if you forget to register your class in persistence.xml.

laktak
  • 57,064
  • 17
  • 134
  • 164