Package org.hibernate.query
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 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(); ... }
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:
KeyedPage
,SelectionQuery.getKeyedResultList(KeyedPage)
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<List<?>>
getKeyList()
The keys of the results, in order.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.KeyedPage<R>
getPage()
The size and approximate page number of the current page.KeyedPage<R>
getPreviousPage()
The specification of the previous page of results, ornull
if it is known that this is the first page.List<R>
getResultList()
The results on the current page.boolean
isFirstPage()
boolean
isLastPage()
-
-
-
Method Detail
-
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, 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.
-
-