Spring Data JPA offers Page<T> and Slice<T> for pagination. This post explains the SQL differences, performance trade‑offs, and how to pick the right option for large tables and infinite‑scroll UIs.
Learn how to add limit‑and‑offset pagination to Hibernate queries, ensure deterministic ordering, and verify the generated SQL with logging and unit tests.
Learn how to implement server‑side pagination using Hibernate's Criteria API to prevent OutOfMemoryErrors and optimize database performance through setFirstResult and setMaxResults.
Learn how to identify and fix the N+1 select problem in Hibernate ORM using JOIN FETCH, Entity Graphs, and BatchSize to eliminate repetitive database queries.
Hibernate's setFirstResult/setMaxResults paginate in the database — until a collection fetch join silently moves pagination into JVM memory. Here's how to spot it, fix it with a two-step query, and when to switch to keyset pagination.
A diagnostic path for Hibernate LazyInitializationException: locate the session boundary that closed too early, then pick a fix that matches the finding.
Hibernate ORM exposes setFirstResult() and setMaxResults() on Query and TypedQuery to paginate results, delegating to the configured dialect to emit LIMIT / OFFSET or ROWNUM clauses. When a query fetches a collection association, the framework may log HHH000104: firstResult/maxResults specified with collection fetch; applying in memory! and shift pagination
guys. I'm having a problem with a Spring boot 2.3.0 and PostgreSQL 12 project. I have an entity class I called User whose code is as follows: @Entity @NoArgsConstructor @Data @AllArgsConstructor @Builder public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String username; private String email; private String f