How to handle count query in Spring Data JPA Pageable?
interface BookRepository : JpaRepository<Book, Isbn>, KotlinJdslJpqlExecutor
val page: Page<Book> = bookRepository.findPage(pageable,
{ // Query
select(
entity(Book::class)
).from(
entity(Book::class),
join(Book::author)
).where(
// ... some conditions
).groupBy(
path(Book::isbn)
)
},
{ // Count Query
select(
countDistinct(path(Book::isbn))
).from(
entity(Book::class),
join(Book::author)
).where(
// ... same conditions
)
}
)Last updated