EntityManager fetch reach vs Spring Data JPA Pageable pagination consistency
0 reputation · 29 Jan 2023, 01:40 UTC
A design decision is needed for the interoperability boundary between Hibernate EntityManager fetch reach and Spring Data JPA Pageable pagination. The goal is a predictable entity graph depth when repository methods return paged results backed by JPA entities with associations.
Hibernate fetch mode LAZY or EAGER determines the reach of associated entities during query execution. Spring Data JPA Pageable adds pagination semantics and a separate count query. The interaction is uncertain when fetch reach expectations cross the ORM and repository layers, and version-specific defaults for fetch reach can change downstream pagination behavior. LAZY reach combined with pagination also raises session lifecycle constraints, and count queries may not respect fetch reach, affecting page totals.
What contract should define fetch reach across EntityManager and Spring Data JPA Pageable? Should reach be standardized in the repository interface or remain ORM-local? How should count query semantics relate to fetch reach for consistent page metadata?