-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Specification<T>.toPredicate(...) Change type of first parameter to From<?, T> #2761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
From an API perspective, This could be a topic worth revisiting for Spring Data JPA 4.0. |
Another approach here could be the introduction of a functional-style composition API to build and reuse specification-like fragments. Anyone willing to experiment with that kind of approach can take a spike and we're happy to keep the discussion going. |
when we are at it, why not |
With a Path you would not be able to join or correlate, so From<T,T> seems to be a nice fit. |
I've put together a possible implementation based on how we handle it in our project. Due to limitations with modifying Spring classes, our local solution includes a bit more code duplication. We make extensive use of NestableSpecification and JoinSpecification, often nesting them across multiple relations. Our specifications always implement NestableSpecification instead of Specification, since our predicates do not need access to the Root and From is always sufficient. If you're interested, I'm happy to flesh out the implementation further with documentation and tests. |
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 bothRoot<T>
andJoin<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
andCar
.We would like to reuse these 2 methods when filtering on both CarMaker and Car:
see also: https://stackoverflow.com/a/46955740/6705221
The text was updated successfully, but these errors were encountered: