Package org.hibernate.query
Class KeyedResultList<R>
java.lang.Object
org.hibernate.query.KeyedResultList<R>
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe keys of the results, in order.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.getPage()
The size and approximate page number of the current page.The specification of the previous page of results, ornull
if it is known that this is the first page.The results on the current page.boolean
boolean
-
Constructor Details
-
KeyedResultList
-
-
Method Details
-
getResultList
The results on the current page. -
getKeyList
The keys of the results, in order. -
getPage
The size and approximate page number of the current page. -
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
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.
-