JHipster Repository ↔ Spring Data JPA Pageable: How to enforce a global max page size?
0 reputation · 14 Dec 2024, 01:39 UTC
In a JHipster‑generated application the REST controllers expose CRUD endpoints that accept a Pageable object. The controller delegates to a Spring Data JPA repository and uses PaginationUtil to add X‑Total‑Count and Link headers. The framework accepts any pageSize value supplied by the client; the default is 20 but larger values are not capped.
Because the generated code does not impose a hard limit, a very large pageSize can lead to excessive memory consumption, long query times, and potential denial‑of‑service. The application has no global configuration to enforce a maximum, and any custom validation would need to be applied consistently across all endpoints while preserving the correct pagination metadata.
What is the recommended approach to enforce a global maximum page size in a JHipster application that uses Spring Data JPA Pageable? Should the solution be a custom Pageable implementation, a request filter, or a global exception handler that validates the size? How can the chosen method coexist with PaginationUtil so that the X‑Total‑Count and Link headers remain accurate?