Hibernate Query pagination with JOIN FETCH and database limit/offset
0 reputation · 12 Aug 2024, 23:19 UTC
The goal is to configure Hibernate ORM pagination via setFirstResult and setMaxResults so that LIMIT/OFFSET is generated by the dialect and the database applies paging before results are materialized.
The queries use JOIN FETCH to load an entity graph in a single round trip. Dialect support for limit/offset can vary by query structure, and Hibernate may fall back to loading the full result set when it considers database-level pagination unsafe. The exact permission boundary for when fallback is allowed is unclear.
Assuming recent Hibernate ORM versions, what configuration controls whether in-memory pagination is permitted for JOIN FETCH queries? How is dialect capability evaluated for a specific query shape? What is the documented behavior when limit/offset cannot be applied safely to a fetch join?