Interface PanacheQuery<Entity,EntityList,Confirmation,Count>
- Type Parameters:
Entity- The entity type being queried
- All Known Subinterfaces:
PanacheBlockingQuery<Entity>,PanacheReactiveQuery<Entity>
- All Known Implementing Classes:
PanacheBlockingQueryImpl,PanacheManagedReactiveQueryImpl,PanacheStatelessReactiveQueryImpl
Interface representing an entity query, which abstracts the use of paging, getting the number of results, and
operating on List or Stream.
Instances of this interface cannot mutate the query itself or its parameters: only paging information can be modified, and instances of this interface can be reused to obtain multiple pages of results.
- Author:
- Stéphane Épardaud
-
Method Summary
Modifier and TypeMethodDescriptioncount()Reads and caches the total number of entities this query operates on.Enables a Hibernate filter during fetching of results for this query.Enables a Hibernate filter during fetching of results for this query.Sets the current page to the first pageReturns the first result of the current page index.Returns true if there is another page to read after the current one.Returns true if there is a page to read before the current one.lastPage()Sets the current page to the last page.list()Returns the current page of results as aList.nextPage()Sets the current page to the next pageorg.hibernate.query.Pagepage()Returns the current page.page(int pageIndex, int pageSize) Sets the current page.page(org.hibernate.query.Page page) Sets the current page.Returns the total number of pages to be read using the current page size.Sets the current page to the previous page (or the first page if there is no previous page)range(int startIndex, int lastIndex) Switch the query to use a fixed range (start index - last index) instead of a page.Executes this query for the current page and return a single result.Set a query property or hint on the underlying JPA Query.withLock(jakarta.persistence.LockModeType lockModeType) Define the locking strategy used for this query.
-
Method Details
-
page
Sets the current page.- Parameters:
page- the new page- Returns:
- this query, modified
- See Also:
-
page
Sets the current page.- Parameters:
pageIndex- the page index (0-based)pageSize- the page size- Returns:
- this query, modified
- See Also:
-
nextPage
PanacheQuery<Entity,EntityList, nextPage()Confirmation, Count> Sets the current page to the next page- Returns:
- this query, modified
- Throws:
UnsupportedOperationException- if a page hasn't been set or if a range is already set- See Also:
-
previousPage
PanacheQuery<Entity,EntityList, previousPage()Confirmation, Count> Sets the current page to the previous page (or the first page if there is no previous page)- Returns:
- this query, modified
- Throws:
UnsupportedOperationException- if a page hasn't been set or if a range is already set- See Also:
-
firstPage
PanacheQuery<Entity,EntityList, firstPage()Confirmation, Count> Sets the current page to the first page- Returns:
- this query, modified
- Throws:
UnsupportedOperationException- if a page hasn't been set or if a range is already set- See Also:
-
lastPage
PanacheQuery<Entity,EntityList, lastPage()Confirmation, Count> Sets the current page to the last page. This will cause reading of the entity count.- Returns:
- this query, modified
- Throws:
UnsupportedOperationException- if a page hasn't been set or if a range is already set- See Also:
-
hasNextPage
Confirmation hasNextPage()Returns true if there is another page to read after the current one. This will cause reading of the entity count.- Returns:
- true if there is another page to read
- Throws:
UnsupportedOperationException- if a page hasn't been set or if a range is already set- See Also:
-
hasPreviousPage
Confirmation hasPreviousPage()Returns true if there is a page to read before the current one.- Returns:
- true if there is a previous page to read
- Throws:
UnsupportedOperationException- if a page hasn't been set or if a range is already set- See Also:
-
pageCount
Count pageCount()Returns the total number of pages to be read using the current page size. This will cause reading of the entity count.- Returns:
- the total number of pages to be read using the current page size.
- Throws:
UnsupportedOperationException- if a page hasn't been set or if a range is already set
-
page
org.hibernate.query.Page page()Returns the current page.- Returns:
- the current page
- Throws:
UnsupportedOperationException- if a page hasn't been set or if a range is already set- See Also:
-
range
Switch the query to use a fixed range (start index - last index) instead of a page. As the range is fixed, subsequent pagination of the query is not possible.- Parameters:
startIndex- the index of the first element, starting at 0lastIndex- the index of the last element- Returns:
- this query, modified
-
withLock
PanacheQuery<Entity,EntityList, withLockConfirmation, Count> (jakarta.persistence.LockModeType lockModeType) Define the locking strategy used for this query.- Parameters:
lockModeType- the locking strategy to be used for this query.- Returns:
- this query, modified
-
withHint
Set a query property or hint on the underlying JPA Query.- Parameters:
hintName- name of the property or hint.value- value for the property or hint.- Returns:
- this query, modified
-
filter
PanacheQuery<Entity,EntityList, filterConfirmation, Count> (String filterName, Map<String, Object> parameters) Enables a Hibernate filter during fetching of results for this query. Your filter must be declared with
FilterDefon your entity or package, and enabled withFilteron your entity.WARNING: setting filters can only be done on the underlying Hibernate
Sessionand so this will modify the session's filters for the duration of obtaining the results (not while building the query). Enabled filters will be removed from the session afterwards, but no effort is made to preserve filters enabled on the session outside of this API.- Parameters:
filterName- The name of the filter to enableparameters- The set of parameters for the filter, if the filter requires parameters- Returns:
- this query, modified
-
filter
Enables a Hibernate filter during fetching of results for this query. Your filter must be declared with
FilterDefon your entity or package, and enabled withFilteron your entity.WARNING: setting filters can only be done on the underlying Hibernate
Sessionand so this will modify the session's filters for the duration of obtaining the results (not while building the query). Enabled filters will be removed from the session afterwards, but no effort is made to preserve filters enabled on the session outside of this API.- Parameters:
filterName- The name of the filter to enable- Returns:
- this query, modified
-
count
Count count()Reads and caches the total number of entities this query operates on. This causes a database query withSELECT COUNT(*)and a query equivalent to the current query, minus ordering.- Returns:
- the total number of entities this query operates on, cached.
-
list
EntityList list()Returns the current page of results as aList.- Returns:
- the current page of results as a
List. - See Also:
-
firstResult
Entity firstResult()Returns the first result of the current page index. This ignores the current page size to fetch a single result.- Returns:
- the first result of the current page index, or null if there are no results.
- See Also:
-
singleResult
Entity singleResult()Executes this query for the current page and return a single result.- Returns:
- the single result (throws if there is not exactly one)
- Throws:
jakarta.persistence.NoResultException- if there is no resultjakarta.persistence.NonUniqueResultException- if there are more than one result- See Also:
-