Class KeyedResultList<R>

java.lang.Object
org.hibernate.query.KeyedResultList<R>

@Incubating public class KeyedResultList<R> extends Object
Support for pagination based on a unique key of the result set instead of the offset. An instance of this class represent a page of results returned by SelectionQuery.getKeyedResultList(KeyedPage). The actual query results are held in getResultList().

An idiom for iterating pages of keyed results is:

var query =
        session.createQuery("where title like :title", Book.class)
                .setParameter("title", "%Hibernate%");
var resultList =
        query.getKeyedResultList(first(10).keyedBy(asc(Book_.isbn)));
var results = resultList.getResultList();
...
while ( !resultList.isLastPage() ) {
    resultList = query.getKeyedResultList(resultList.getNextPage());
    results = resultList.getResultList();
    ...
}

When KeyedResultList is the declared return type of a finder method or HQL query method, the idiom may be written:

var resultList =
        books.byTitle("%Hibernate%", first(10).keyedBy(asc(Book_.isbn)));
var results = resultList.getResultList();
...
while ( !resultList.isLastPage() ) {
    resultList = books.byTitle("%Hibernate%", resultList.getNextPage());
    results = resultList.getResultList();
    ...
}
Since:
6.5
See Also:
API Note:
This class is similar to jakarta.data.page.CursoredPage, and is used by Hibernate Data Repositories to implement Jakarta Data query methods.
  • Constructor Details

  • Method Details

    • getResultList

      public List<R> getResultList()
      The results on the current page.
    • getKeyList

      public List<List<?>> getKeyList()
      The keys of the results, in order.
    • getPage

      public KeyedPage<R> getPage()
      The size and approximate page number of the current page.
    • getNextPage

      public KeyedPage<R> getNextPage()
      The specification of the next page of results, if there are more results, or null if it is known that there are no more results after this page.
    • getPreviousPage

      public KeyedPage<R> getPreviousPage()
      The specification of the previous page of results, or null if it is known that this is the first page.
    • isLastPage

      public boolean isLastPage()
      Returns:
      true if this is known to be the last page of results.
    • isFirstPage

      public boolean isFirstPage()
      Returns:
      true if this is the first page of results.