JPA - ReportQuery没有属性

时间:2015-11-01 08:03:58

标签: jpa eclipselink jpa-2.0

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

  

异常[EclipseLink-6088](Eclipse Persistence Services - 2.0.2.v20100323-r6872):org.eclipse.persistence.exceptions.QueryException   异常描述:ReportQuery没有属性。   查询: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);
        ......

    }

1 个答案:

答案 0 :(得分:1)

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

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