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 ?

4

2 回答 2

1

您的查询未完成。您应该添加SELECTFROM子句。

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();
于 2013-11-01T21:33:56.400 回答
0

你应该使用

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

代替

CriteriaQuery _criteriaquery = EM.getCriteriaBuilder().createQuery(Clazz);
于 2013-11-01T21:33:06.553 回答