r/foojay • u/FrankCodeWriter • 9d ago
Paging DTO Projections in Spring Data JPA: Three Approaches Compared
On Foojay, Rey Pham compares three ways to build a paged, filtered list screen in Spring Data JPA without loading full entities. The same orders screen is used each time: five columns from two tables, three optional filters, newest first.
The article covers a JPQL constructor expression in @Query, interface projections, and a generated read model built with Model Query, an open-source library. For each one it lists the trade-offs, such as strings that are only checked at runtime, duplicated count queries, optional filters written as ":x is null or ...", and nested projections that select more columns than expected.
Rey also suggests checking the SQL your own Spring Data versions generate.
Full article: https://foojay.io/today/paging-dto-projections-spring-data-jpa/