I am writing spring data jpa using Specification. but the IDEA give me a error(red line):
'select(javax.persistence.criteria.Selection<? extends capture<?>>)' in 'javax.persistence.criteria.CriteriaQuery' cannot be applied to '(javax.persistence.criteria.Root<cn.lvxg.po.ClassRoom>)'
here is my code. please help me!
the Root is subclass of Selection. why my code is wrong?
I am really suffering from this problem.
Specification<Student> specification = new Specification<Student>() {
public Predicate toPredicate(Root<Student> root,//
CriteriaQuery<?> criteriaQuery,
CriteriaBuilder criteriaBuilder) {
Root<ClassRoom> classRoomRoot = criteriaQuery.from(ClassRoom.class);
Root<Student> studentRoot = criteriaQuery.from(Student.class);
criteriaQuery.select(classRoomRoot)
.distinct(true)
.where(criteriaBuilder.equal(studentRoot,classRoomRoot.get("id")));
return criteriaQuery.getRestriction();;
}
};
Pageable pageable = new PageRequest(0, 5);
Page<Student> studentsPage = jpaSpecificationRepository.findAll(specification, pageable);