Annotation Interface OrderBy
Annotates a repository method to request sorting of results.
When multiple OrderBy annotations are specified on a
repository method, the precedence for sorting follows the order
in which the OrderBy annotations are specified,
and after that follows any sort criteria that are supplied
dynamically by Sort parameters or by any Sort.Order parameter.
For example, the following sorts first by the
lastName attribute in ascending order,
and secondly, for entities with the same lastName,
it then sorts by the firstName attribute,
also in ascending order. For entities with the same
lastName and firstName.
@OrderBy("lastName")
@OrderBy("firstName")
@OrderBy("id")
Person[] findByZipCode(int zipCode, Pageable pageable);
The interpretation of ascending and descending order is determined by the database, but, in general:
- ascending order for numeric values is the natural order with smaller numbers before larger numbers,
- ascending order for string values is lexicographic order with
AbeforeZ, and - ascending order for boolean values places
falsebeforetrue.
A repository method with an @OrderBy annotation must not
have:
- the Query by Method Name
OrderBykeyword in its name, nor - a
@Queryannotation specifying a JDQL or JPQL query with anORDER BYclause.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic @interfaceEnables multipleOrderByannotations on the method. -
Required Element Summary
Required Elements -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanIndicate whether to use descending order when sorting by this attribute.booleanIndicates whether or not to request case insensitive ordering from a database with case sensitive collation.
-
Element Details
-
value
String valueEntity attribute name to sort by.
For example,
@OrderBy("age") Stream<Person> findByLastName(String lastName);- Returns:
- entity attribute name.
-
-
-
descending
boolean descendingIndicate whether to use descending order when sorting by this attribute.
The default value of
falsemeans ascending sort.- Returns:
- whether to use descending (versus ascending) order.
- Default:
- false
-
ignoreCase
boolean ignoreCaseIndicates whether or not to request case insensitive ordering from a database with case sensitive collation. A database with case insensitive collation performs case insensitive ordering regardless of the requested
ignoreCasevalue.The default value is
false.- Returns:
- whether or not to request case insensitive sorting for the property.
- Default:
- false
-