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 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 to
jakarta.data.page.CursoredPage, and is used by Hibernate Data Repositories to implement Jakarta Data query methods.
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionThe keys of the results, in order.The specification of the next page of results, if there are more results, ornullif it is known that there are no more results after this page.getPage()Thesize and approximatepage number of the current page.The specification of the previous page of results, ornullif it is known that this is the first page.The results on the current page.booleanboolean
Constructor Details
KeyedResultList
Method Details
getResultList
The results on the current page.getKeyList
The keys of the results, in order.getPage
Thesize and approximatepage number of the current page.getNextPage
The specification of the next page of results, if there are more results, ornullif it is known that there are no more results after this page.getPreviousPage
The specification of the previous page of results, ornullif it is known that this is the first page.isLastPage
public boolean isLastPage()- Returns:
trueif this is known to be the last page of results.
isFirstPage
public boolean isFirstPage()- Returns:
trueif this is the first page of results.