In my Spring data repository, I (should) use custom queries using annotation @Query. I know that I can limit the number of results in a named query like
Iterable<Person> findFirst5OrderByLastName()
or that you can limit the number of results by passing a page like
Iterable<Person> findByLastName(String lastName, Pageable pageable)
But is it possible to achieve this using custom annotation @Query?
TIA
EDIT
since I see that my question is a bit confusing, some clarifications: I want to limit the number of results obtained when using a custom query so that I don’t
1) you need to specify the size of the result through the page
2) you must use a named query to indicate the size of the result
In fact, I want the limit on the number of results to be completely transparent when calling a method (therefore, not passed Pageable) and not rely on the Spring Data naming scheme (it is best to pass through a user name as the method value / function)
source
share