【发布时间】:2019-05-06 22:16:54
【问题描述】:
我们如何使用规范编写下面的查询
SELECT e.id, e.name, count(e.id)
FROM Employee e INNER JOIN Department d
WHERE e.id = d.empId;
当我们使用规范时,即使在多选中提到它也不会选择count()。
任何想法,当我们使用 JPA findAll 方法时,如何在规范中包含计数列。
尝试了多选,但是当它传递给规范时,它只查询非聚合列。
Expression<Long> countExp = cb.count(root.get("id"));
CriteriaQuery<Employee> select =
criteriaQuery.multiselect(root.get("id"), root.get("name"), countExp);
但它会生成如下查询:
SELECT e.id, e.name
FROM Employee e INNER JOIN Department d
WHERE e.id = d.empId;
似乎有同样的问题: JpaSpecificationExecutor : complex queries with specifications
【问题讨论】:
标签: jpa spring-data-jpa specifications