Package org.hibernate.query
Class Order<X>
java.lang.Object
org.hibernate.query.Order<X>
- Type Parameters:
X
- The result type of the query to be sorted
A rule for sorting a query result set.
This is a convenience class which allows query result ordering
rules to be passed around the system before being applied to
a Query
by calling SelectionQuery.setOrder(Order)
.
session.createSelectionQuery("from Book b join b.authors a where a.name = :name", Book.class) .setParameter("name", authorName) .setOrder(asc(Book_.publicationDate)) .getResultList();
Order
s may be stacked using List.of()
and
SelectionQuery.setOrder(List)
.
session.createSelectionQuery("from Book b join b.authors a where a.name = :name", Book.class) .setParameter("name", authorName) .setOrder(List.of(asc(Book_.publicationDate), desc(Book_.ssn))) .getResultList();
A parameter of a finder method or HQL query method may be declared with type Order<? super E>
,
List<Order<? super E>>
, or Order<? super E>...
(varargs)
where E
is the entity type returned by the query.
- Since:
- 6.3
- See Also:
- API Note:
- This class is similar to
jakarta.data.Sort
, and is used by Hibernate Data Repositories to implement Jakarta Data query methods.
-
Method Summary
Modifier and TypeMethodDescriptionasc
(int element) An order where the result set is sorted by the select item in the given position with smaller values first.static <T> Order<T>
asc
(SingularAttribute<T, ?> attribute) An order where an entity is sorted by the given attribute, with smaller values first.static <T> Order<T>
An order where an entity of the given class is sorted by the attribute with the given name, with smaller values first.by
(int element, SortDirection direction) An order where the result set is sorted by the select item in the given position, in the given direction.by
(int element, SortDirection direction, boolean ignoreCase) An order where the result set is sorted by the select item in the given position in the given direction, with the specified case-sensitivity.by
(int element, SortDirection direction, Nulls nullPrecedence) An order where the result set is sorted by the select item in the given position in the given direction, with the specified precedence for null values.static <T> Order<T>
by
(SingularAttribute<T, ?> attribute, SortDirection direction) An order where an entity is sorted by the given attribute, in the given direction.static <T> Order<T>
by
(SingularAttribute<T, ?> attribute, SortDirection direction, boolean ignoreCase) An order where an entity is sorted by the given attribute, in the given direction, with the specified case-sensitivity.static <T> Order<T>
by
(SingularAttribute<T, ?> attribute, SortDirection direction, Nulls nullPrecedence) An order where an entity is sorted by the given attribute, in the given direction, with the specified precedence for null values.static <T> Order<T>
by
(Class<T> entityClass, String attributeName, SortDirection direction) An order where an entity of the given class is sorted by the attribute with the given name, in the given direction.static <T> Order<T>
by
(Class<T> entityClass, String attributeName, SortDirection direction, boolean ignoreCase) An order where an entity of the given class is sorted by the attribute with the given name, in the given direction, with the specified case-sensitivity.static <T> Order<T>
by
(Class<T> entityClass, String attributeName, SortDirection direction, Nulls nullPrecedence) An order where an entity of the given class is sorted by the attribute with the given name, in the given direction.desc
(int element) An order where the result set is sorted by the select item in the given position with larger values first.static <T> Order<T>
desc
(SingularAttribute<T, ?> attribute) An order where an entity is sorted by the given attribute, with larger values first.static <T> Order<T>
An order where an entity of the given class is sorted by the attribute with the given name, with larger values first.boolean
int
int
hashCode()
ignoringCaseIf
(boolean ignoreCase) An order based on this order, possibly without case-sensitivity.boolean
reverse()
Reverse the direction of the given ordering listreversedIf
(boolean reverse) An order based on this order, possibly reversed.toString()
-
Method Details
-
asc
An order where an entity is sorted by the given attribute, with smaller values first. If the given attribute is of textual type, the ordering is case-sensitive. -
desc
An order where an entity is sorted by the given attribute, with larger values first. If the given attribute is of textual type, the ordering is case-sensitive. -
by
An order where an entity is sorted by the given attribute, in the given direction. If the given attribute is of textual type, the ordering is case-sensitive. -
by
public static <T> Order<T> by(SingularAttribute<T, ?> attribute, SortDirection direction, boolean ignoreCase) An order where an entity is sorted by the given attribute, in the given direction, with the specified case-sensitivity. -
by
public static <T> Order<T> by(SingularAttribute<T, ?> attribute, SortDirection direction, Nulls nullPrecedence) An order where an entity is sorted by the given attribute, in the given direction, with the specified precedence for null values. If the given attribute is of textual type, the ordering is case-sensitive. -
asc
An order where an entity of the given class is sorted by the attribute with the given name, with smaller values first. If the named attribute is of textual type, the ordering is case-sensitive. -
desc
An order where an entity of the given class is sorted by the attribute with the given name, with larger values first. If the named attribute is of textual type, the ordering is case-sensitive. -
by
An order where an entity of the given class is sorted by the attribute with the given name, in the given direction. If the named attribute is of textual type, the ordering is case-sensitive. -
by
public static <T> Order<T> by(Class<T> entityClass, String attributeName, SortDirection direction, boolean ignoreCase) An order where an entity of the given class is sorted by the attribute with the given name, in the given direction, with the specified case-sensitivity. -
by
public static <T> Order<T> by(Class<T> entityClass, String attributeName, SortDirection direction, Nulls nullPrecedence) An order where an entity of the given class is sorted by the attribute with the given name, in the given direction. If the named attribute is of textual type, with the specified precedence for null values. If the named attribute is of textual type, the ordering is case-sensitive. -
asc
An order where the result set is sorted by the select item in the given position with smaller values first. If the item is of textual type, the ordering is case-sensitive. -
desc
An order where the result set is sorted by the select item in the given position with larger values first. If the item is of textual type, the ordering is case-sensitive. -
by
An order where the result set is sorted by the select item in the given position, in the given direction. If the item is of textual type, the ordering is case-sensitive. -
by
An order where the result set is sorted by the select item in the given position in the given direction, with the specified case-sensitivity. -
by
An order where the result set is sorted by the select item in the given position in the given direction, with the specified precedence for null values. If the named attribute is of textual type, the ordering is case-sensitive. -
getDirection
-
getNullPrecedence
-
isCaseInsensitive
public boolean isCaseInsensitive() -
getAttribute
-
getEntityClass
-
getAttributeName
-
getElement
public int getElement() -
reverse
- Returns:
- this order, but with the sorting direction reversed.
- Since:
- 6.5
-
ignoringCase
- Returns:
- this order, but without case-sensitivity.
- Since:
- 6.5
-
withNullsFirst
- Returns:
- this order, but with nulls sorted first.
- Since:
- 6.5
-
withNullsLast
- Returns:
- this order, but with nulls sorted last.
- Since:
- 6.5
-
reversedIf
An order based on this order, possibly reversed.- Parameters:
reverse
-true
if the returned order should be reversed- Returns:
- this order, but reversed if the argument is
true
- Since:
- 7.0
- API Note:
- This is a convenience for use with Jakarta Data
-
ignoringCaseIf
An order based on this order, possibly without case-sensitivity.- Parameters:
ignoreCase
-true
if this order should be ignore case- Returns:
- this order, but ignoring case if the argument is
true
- Since:
- 7.0
- API Note:
- This is a convenience for use with Jakarta Data
-
toString
-
equals
-
hashCode
public int hashCode() -
reverse
Reverse the direction of the given ordering list- Parameters:
ordering
- a list ofOrder
items- Returns:
- a new list, with each
Order
reversed - Since:
- 6.5
- See Also:
-