Top Description Methods
org.hibernate.annotations

public @Interface SQLOrder

extends Annotation
Annotations
@Target:METHOD, FIELD
@Retention:RUNTIME
Imports
java.lang.annotation.Retention, .Target

Order a collection using an expression or list of expression written in native SQL. For example, @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.util.Set or java.util.Map, the order is maintained using a java.util.LinkedHashSet or java.util.LinkedHashMap. If the collection is a bag or java.util.List, the order is maintained by the underlying java.util.ArrayList.

There are several other ways to order or sort a collection:

It's illegal to use SQLOrder together with the JPA-defined jakarta.persistence.OrderBy for the same collection.

Authors
Gavin King, Emmanuel Bernard, Steve Ebersole
Since
6.3
See Also
jakarta.persistence.OrderBy, SortComparator, SortNatural, DialectOverride.SQLOrder

Method Summary

Modifier and TypeMethod and Description
public String
value()

A comma-separated list native SQL expressions used to sort the collection elements.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback 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:

  • asc-ending or desc-ending order, or even
  • nulls first or nulls last.
Hibernate does not interpret these keywords, and simply passes them through to the generated SQL.