How can we write below query using Specification
SELECT e.id, e.name, count(e.id)
FROM Employee e INNER JOIN Department d
WHERE e.id = d.empId;
When we are using Specification, it is not selecting count() even it is mentioned in multiselect.
Any idea, how to include count column in Specification when we are using JPA findAll method.
Tried with multiselect, but when it passed to specification then it query only on non-aggregated columns.
Expression<Long> countExp = cb.count(root.get("id"));
CriteriaQuery<Employee> select =
criteriaQuery.multiselect(root.get("id"), root.get("name"), countExp);
But it generates query like :
SELECT e.id, e.name
FROM Employee e INNER JOIN Department d
WHERE e.id = d.empId;
Seems having same issue as: JpaSpecificationExecutor : complex queries with specifications