Package org.hibernate.annotations
Annotation Interface OrderBy
@Target({METHOD,FIELD})
@Retention(RUNTIME)
@Deprecated(since="6.3",
forRemoval=true)
public @interface OrderBy
Deprecated, for removal: This API element is subject to removal in a future version.
Order a collection using an expression written in native SQL.
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 Set
or Map
,
the order is maintained using a LinkedHashSet
or
LinkedHashMap
. If the collection is a bag or
List
, the order is maintained by the underlying
ArrayList
.
There are several other ways to order or sort a collection:
- Use the JPA-defined
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. - Use
SortComparator
to sort the collection in memory using aComparator
, orSortNatural
to sort the collection in memory according to its natural order. - Use
OrderColumn
to maintain the order of aList
with a dedicated index column.
It's illegal to use OrderBy
together with the JPA-defined
OrderBy
for the same collection.
-
Required Element Summary
Required Elements
-
Element Details
-
clause
String clauseDeprecated, for removal: This API element is subject to removal in a future version.The native SQL expression used to sort the collection elements.
-
SQLOrder
instead. This annotation will be removed eventually, since its unqualified name collides withOrderBy
.