@SQLOrder("first_name, last_name"),
@SQLOrder("char_length(name) desc"), or even
@SQLOrder("name asc nulls last").
The order is applied by the database when the collection is fetched, but is not maintained by operations that mutate the collection in memory.
If the collection is a java. or java.,
the order is maintained using a java. or
java.. If the collection is a bag or
java., the order is maintained by the underlying
java..
There are several other ways to order or sort a collection:
jakarta.persistence.OrderBy annotation
to order using an expression written in HQL/JPQL. Since HQL is more
portable between databases, this is the preferred alternative most
of the time.
SortComparator to sort the collection in memory using
a java.util.Comparator , or SortNatural to sort the
collection in memory according to its natural order.
jakarta.persistence.OrderColumn to maintain the order
of a java.util.List with a dedicated index column.
It's illegal to use SQLOrder together with the JPA-defined
jakarta. for the same collection.
jakarta.persistence.OrderBy , SortComparator, SortNatural, DialectOverride.SQLOrder
| Modifier and Type | Method and Description |
|---|---|
| public String |
| value | back to summary |
|---|---|
| public String value() A comma-separated list native SQL expressions used to sort the collection elements. Each element of the list may optionally specify:
| |