I use spring boot 3
School have a one to many relation with Teacher
I created 2 specfication
public Page<School> advanceSearch(SchoolSearch search, Pageable page) {
Specification<School> hasCityName = (Root<School> mainRoot, CriteriaQuery<?> mainCq, CriteriaBuilder mainCb) -> {
...
Predicate predicate..
return predicate;
};
Specification<Teacher> hasTeacherName = (Root<Teacher> mainRoot, CriteriaQuery<?> mainCq, CriteriaBuilder mainCb) -> {
...
Predicate predicate..
return predicate;
};
return findAll(hasCityName, page);
}
I search to do
select s from School s where s.city like city and
s.schoolId in
(select t.school.schooId from Teacher t where t.name like teacherNom)
how to do a in condition with specfication?
I tried with no success
Specification<Teacher> fromRepondant = (Root<Teacher> root, CriteriaQuery<?> cq, CriteriaBuilder cb) -> {
Predicate pre = cb.and(cb.equal(root.get("name"), search.name()));
Path<School> schooPath = root.get("school");
return cq.select(schooPath.get("schoolId")).from(School.class).in(pre);
};
Specification<School> hasIdIn = (Root<School> root, CriteriaQuery<?> cq, CriteriaBuilder cb) -> {
return cb.and(root.get("schooId").in(hasTeacherName));
};