Package org.hibernate.query
Class Page
java.lang.Object
org.hibernate.query.Page
Identifies a page of query results by page size
and page number. This is an alternative to the
use of the JPA-defined operations
SelectionQuery.setFirstResult(int)
and SelectionQuery.setMaxResults(int)
.
session.createSelectionQuery("from Book b join b.authors a where a.name = :name", Book.class) .setParameter("name", authorName) .setPage(Page.first(100)) .getResultList();
This is a convenience class which allows a reference to a page of
results to be passed around the system before being applied to a
Query
by calling Query.setPage(Page)
.
A parameter of a finder method or HQL query method may be declared with type Page
.
For key-based pagination, call keyedBy(Order)
to obtain a
KeyedPage
.
- Since:
- 6.3
- See Also:
- API Note:
- This class is similar to
jakarta.data.page.PageRequest
, and is used by Hibernate Data Repositories to implement Jakarta Data query methods.
-
Method Summary
Modifier and TypeMethodDescriptionfirst()
static Page
first
(int size) Obtain an initial page with the given size.int
int
int
The page number, where0
is the first page.int
getSize()
The size of the page, that is, the maximum number of results on the page.boolean
isFirst()
<R> KeyedPage<R>
Obtain a key-based specification of this page.<R> KeyedPage<R>
Obtain a key-based specification of this page.next()
Obtain the next page with the same size as this page.static Page
page
(int size, int number) Obtain a page, numbered from0
, with the given size.previous()
Obtain the previous page with the same size as this page.
-
Method Details
-
getSize
public int getSize()The size of the page, that is, the maximum number of results on the page. -
getNumber
public int getNumber()The page number, where0
is the first page. -
isFirst
public boolean isFirst()- Returns:
true
is this is the first page.
-
getMaxResults
public int getMaxResults()- Returns:
- the page size, that is, the maximum number of results on the page.
-
getFirstResult
public int getFirstResult()- Returns:
- the offset of this page.
-
page
Obtain a page, numbered from0
, with the given size.- Parameters:
size
- the number of results on the initial page.number
- the number of the page, where0
is the first page.
-
first
Obtain an initial page with the given size.- Parameters:
size
- the number of results on the initial page.
-
next
Obtain the next page with the same size as this page. -
previous
Obtain the previous page with the same size as this page.- Throws:
IllegalStateException
- if this is the first page
-
first
-
keyedBy
Obtain a key-based specification of this page. -
keyedBy
Obtain a key-based specification of this page.
-