Is there possibility to use limit
or setMaxResults
using Spring-Data-JPA Specification?
I can use it via Criteria
or JPQL
, but I need only via specifications.
Specifications have CriteriaQuery
, not a Query
. So, there is no setMaxResults
method.
I think you only have two options:
Use Pageable with your Specification:
Pageable limit = new PageRequest(0,10);
repo.findAll(spec, limit);
or do a workaround like this one: https://gist.github.com/tcollins/0ebd1dfa78028ecdef0b. All the credits to @tcollins
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With