Class Page

java.lang.Object
org.hibernate.query.Page

@Incubating public class Page extends Object
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 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, where 0 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

      public static Page page(int size, int number)
      Obtain a page, numbered from 0, with the given size.
      Parameters:
      size - the number of results on the initial page.
      number - the number of the page, where 0 is the first page.
    • first

      public static Page first(int size)
      Obtain an initial page with the given size.
      Parameters:
      size - the number of results on the initial page.
    • next

      public Page next()
      Obtain the next page with the same size as this page.
    • previous

      public Page previous()
      Obtain the previous page with the same size as this page.
      Throws:
      IllegalStateException - if this is the first page
    • first

      public Page first()
    • keyedBy

      public <R> KeyedPage<R> keyedBy(Order<? super R> keyDefinition)
      Obtain a key-based specification of this page.
      Parameters:
      keyDefinition - an Order object defining a total order on the result set
      Returns:
      a KeyedPage representing this page
      Since:
      6.5
    • keyedBy

      public <R> KeyedPage<R> keyedBy(List<Order<? super R>> keyDefinition)
      Obtain a key-based specification of this page.
      Parameters:
      keyDefinition - a list of Order objects defining a total order on the result set
      Returns:
      a KeyedPage representing this page
      Since:
      6.5