JPA - ReportQuery 没有属性

JPA - There are no attributes for the ReportQuery

我有下面的代码片段来获取记录数,但是当我执行时,我得到以下

Exception [EclipseLink-6088] (Eclipse Persistence Services - 2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions.QueryException Exception Description: There are no attributes for the ReportQuery. Query: ReportQuery(referenceClass=Employees )

    private Integer countEmployees(EmployeesList<Employees> emp) {

        CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<Long> countQ = criteriaBuilder.createQuery(Long.class);

        Root<Employees> empCount = countQ.from(Employees.class);
        Join<Employees, Department> joinDept = 
            empCount.join(Employees_.deptId, JoinType.LEFT);

        List<Predicate> empListCount = new ArrayList<Predicate>();
        Predicate empNameCount,empOrgCount;

        ......
        countQ.where(predicatesCount);
        ......

    }

您指定了一个 where 子句 'if' 有一个 EmpName,但没有别的。你需要 select 东西。由于您似乎想要计算员工数量,因此您需要添加查询的 "select count(employee)" 部分:

countQ.select(criteriaBuilder.count(empCount));