-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
status: pending-design-workNeeds design work before any code can be developedNeeds design work before any code can be developedtype: enhancementA general enhancementA general enhancement
Description
Dear spring devs,
I'd like to suggest the following change in interface Specification<T>
:
Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder);
to
Predicate toPredicate(From<?, T> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder);
Because From<T, U>
is the supertype of both Root<T>
and Join<T, U>
, it would allow better reuse of specifications when joining tables.
Our use case is the following, we have a OneToMany relation
Table CarMaker <>---> Table Car
We have already made Specification factory methods from Request DTOs for entities CarMaker
and Car
.
We would like to reuse these 2 methods when filtering on both CarMaker and Car:
Specification<CarMaker> filterCarMakers(CarMakerRequestDTO request) { ... }
Specification<Car> filterCars(CarRequestDTO request) { ... }
Specification<CarMaker> filterCarMakersAndCars(CarMakerAndCarAggregatedRequestDTO request) {
return filterCarMakers(request.getCarMakerRequest())
.and((r, q, c) -> filterCars(request.getCarRequest()).toPredicate(r.join("cars", JoinType.INNER), q, c));
}
didisky, nmitchell-bgl, bukajsytlos, jobayle, FoxWulf and 4 more
Metadata
Metadata
Assignees
Labels
status: pending-design-workNeeds design work before any code can be developedNeeds design work before any code can be developedtype: enhancementA general enhancementA general enhancement