I am using the specification and findAll method to retrieve the paginated results that matches to given criteria.
'findAll(spec, pageRequest)' method of 'org.springframework.data.jpa.repository.JpaSpecificationExecutor' interface.
I defined Specification as below.
public static <T> Specification<T> bySearchFilter(final Class<T> clazz) {
return (Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) -> {
query.multiselect(root.get("id")).distinct(true);
List<Predicate> predicates = Lists.newArrayList();
predicates.add(builder.equal(root.get("active"), "Y"));
return builder.and(predicates.toArray(new Predicate[0]));
};
}
query.multiselect(root.get("id"), root.get("name")).distinct(true);
Above snippet giving distinct results but selecting all the columns of the table. But I want only id and name columns.
Am I doing any mistake here?