Я пытаюсь отсортировать Службы по Заданиям, которые находятся в отношениях ManyToMany.
public Page<com.bitweb.syda.data.entity.service.Service> getServicesList(ServiceListRequest request, Pageable pageable, String sort) {
Specification<com.bitweb.syda.data.entity.service.Service> spec = (root, cq, cb) -> {
if(!Long.class.isAssignableFrom(cq.getResultType())) {
if(sort.contains("jobs")) {
Join<com.bitweb.syda.data.entity.service.Service, Job> jobs = root.join("jobs");
//check for asc or desc
cq.groupBy(root.get("id"), jobs.get("id"));
cq.orderBy(cb.asc(jobs.get("name")));
}
}
return null;
};
if (request.getSearch() != null) spec = spec.and(search(request.getSearch()));
if (request.getName() != null) spec = spec.and(name(request.getName()));
if (request.getJobs() != null) spec = spec.and(hasJobs(request.getJobs()));
if (request.getNeedsPatrol() != null) spec = spec.and(needsPatrol(request.getNeedsPatrol()));
return serviceRepository.findAll(spec, pageable);
}
Я получаю ошибку
ERROR: column "job4_.id" must appear in the GROUP BY clause or be used in an aggregate function
И из журналов postgre я вижуконец запроса так:
group by service0_.id , job2_.id order by job4_.id asc
Как я могу заставить это работать?