Package org.hibernate.query

Class KeyedResultList<R>

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

@Incubatingpublic classKeyedResultList<R>extendsObject
Support for pagination based on a unique key of the result set instead of theoffset. An instance of this class represent a page of results returned bySelectionQuery.getKeyedResultList(KeyedPage). The actual query results are held ingetResultList().

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();     ... }

WhenKeyedResultList is the declared return type of afinder method orHQL 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 tojakarta.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()
      Thesize and approximatepage number of the current page.
    • getNextPage

      public KeyedPage<R> getNextPage()
      The specification of the next page of results, if there are more results, ornull 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, ornull 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.