-1
我正在使用規範編寫彈簧數據jpa。但IDEA給我一個錯誤(紅線):爲什麼我的criteriaQuery.select方法在彈簧數據中是錯誤的jpa
'select(javax.persistence.criteria.Selection<? extends capture<?>>)' in 'javax.persistence.criteria.CriteriaQuery' cannot be applied to '(javax.persistence.criteria.Root<cn.lvxg.po.ClassRoom>)'
這是我的代碼。請幫幫我!
根是Selection的子類。爲什麼我的代碼錯了?
我真的患了這個問題。
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);