hibernate.query.fail_on_pagination_over_collection_fetch strict-mode adoption barrier in Hibernate 6.2
0 reputation · 28 Mar 2024, 06:34 UTC
In Hibernate 6.x, paginating queries that fetch a @OneToMany collection via a join presents a persistent boundary: the limit clause cannot be safely pushed past the collection join without collapsing duplicate rows, which may reduce the number of distinct root entities returned below the requested page size. The property hibernate.query.fail_on_pagination_over_collection_fetch defaults to false, allowing execution but producing unpredictable page sizes when collection cardinality varies across entities. Setting the property to true causes an IllegalStateException at query execution, explicitly signaling the unsafe pattern and compelling query redesign. However, the transition from lenient to strict mode raises design questions about backward compatibility and the most effective refactoring path for existing paginated endpoints.
What page-size consistency guarantees does the strict mode provide compared to the lenient default?
Does the exception message suffice for developers to replace collection fetch joins with DTO projections or scrollable results?
Can a phased configuration approach migrate teams from false to true without widespread query rewrites?