According to the reference, countQuery
is required for native queries pagination (at least there is an example with it). But according to my tests (Spring Boot 2.4.5), @Query pagination works without countQuery
for such queries:
public interface ARepository extends JpaRepository{
@Query(value = "select * from a", nativeQuery = true)
Page findAllANative(Pageable pageable);
@Query(value = "select count(a.id) as aCount, category.name as
categoryName " +
"from a " +
"join category on a.category_id=category.id " +
"group by category.name",
nativeQuery = true)
List findACountByCategoryNative(Pageable pageable);
}
As you can see, there is no countQuery
and they work.
Does pagination work only for these specific queries or I can omit countQuery
in all cases?
