Configuring Hibernate join‑fetch pagination with distinct results in Red Hat JBoss EAP
20K reputation · 25 Jun 2020, 09:30 UTC
Goal: Retrieve paginated lists of parent entities with their child associations using Hibernate’s setFirstResult and setMaxResults together with left join fetch, while ensuring each parent appears only once per page.
Constraints: The application runs on Red Hat JBoss EAP 7.x (Hibernate ORM 5.0‑5.6), where the default limit/offset behavior can produce duplicate root entities when join fetching is used. The team must decide whether to rely on a ResultTransformer such as DistinctRootEntityResultTransformer, adopt a keyset‑based (seek) pagination strategy, or use ScrollableResults, considering the effects of high write traffic on result stability and JDBC connection consumption.
Specific questions: Should a DistinctRootEntityResultTransformer be applied to eliminate duplicates without affecting page size? Is keyset‑based pagination more suitable for workloads with frequent inserts/updates? What are the resource trade‑offs between using ScrollableResults and limit/offset with a transformer in a concurrent environment?