I have one entity as Project and I am writing one jpa specification for implementing pagination. Now the problem is I don't want whole entity,I just want some columns of that entity. My specification looks like -
public class ProjectSpecification {
public static Specification<Project> projectListSearchSpec(Set<Long> deptIdList, SearchDto searchDTO) {
return new Specification<Project>() {
@Override
public Predicate toPredicate(Root<Project> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
query.multiselect(root.get("id"));
Predicate all = root.<Project>get("department").get("departmentId").in(deptIdList);
return all;
}
};
}
}
As it can be seen in the snippet that I am trying to use multi-select but there is nor effect of that. I am still getting all the attributes of entity.