Files
spring-data-demo/pagination

pagination

Companion code for Spring Data JPA Pagination and Sorting: Page vs Slice vs Keyset Scrolling (Window API) on ankurm.com.

Component Version
Spring Boot 4.1.2
Spring Data (release train) / Spring Data JPA 2026.0.2 / 4.1.2
Hibernate ORM 7.4.13.Final (7.3.13.Final for the old-behaviour comparison)
H2 (in-memory) 2.4.240
JDK Temurin 25.0.5 LTS

No Docker needed. Every SQL statement is captured by SqlRecorder, a Hibernate StatementInspector, and every test writes what it saw to output/ while asserting the same facts, so the numbers in the post fail the build if they stop being true.

./scripts/run-all.sh             # regenerates every file in output/
./scripts/old-hibernate.sh       # collection-fetch paging on Hibernate 7.3.13.Final
./scripts/other-spring-data.sh   # offset-then-keyset finding on Spring Data 2025.1.8 and 2026.0.0
Source file What it shows
ProductRepository every paging and scrolling form, numbered 1 to 10
ProductController Page vs PagedModel, a keyset cursor endpoint, bad-sort handling
SqlRecorder the SQL capture mechanism
BrokenScrollRepository (test) a String @Query scroll method, which Spring Data rejects
Transcript Shows
output/01-page-slice-list.txt Page runs a count query, Slice and List do not
output/02-slice-boundary.txt how Slice knows there is a next page (n+1 rows)
output/03-count-query-skipped.txt when Spring Data skips the count query
output/04-sorting.txt sort handling and unsafe sort values
output/05-offset-vs-keyset-sql.txt offset SQL vs keyset SQL
output/06-deep-offset-scan-count.txt rows scanned: 10 / 90,010 / 11
output/07-page-drift-insert.txt an insert repeats a row on the next page
output/08-page-drift-delete.txt a delete skips a row
output/09-keyset-ties-and-nulls.txt ties on the sort column, and the id tie-breaker
output/10-query-scroll-unsupported.txt String @Query scroll is rejected
output/11-offset-then-keyset-same-method-*.txt mixing offset and keyset scroll on one method
output/12-collection-fetch-paging-*.txt paging over a collection fetch, per Hibernate version
output/13-pageable-binding.txt what Spring MVC makes of page, size, sort
output/14-page-json-shapes.txt Page vs PagedModel JSON
output/15-rest-bad-sort.txt bad sort values over HTTP
output/16-keyset-cursor-walk.txt walking a dataset with an opaque cursor
output/17-page-json-via-dto.txt serialization-mode=via-dto

There is no docs/ folder: the explanations live in the post.