Skip to content

Commit c88a9ac

Browse files
committed
improve javadoc for @Order/@sort annotations
1 parent 7407791 commit c88a9ac

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

hibernate-core/src/main/java/org/hibernate/annotations/OrderBy.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
66
*/
77
package org.hibernate.annotations;
8+
89
import java.lang.annotation.Retention;
910
import java.lang.annotation.Target;
1011

@@ -13,23 +14,34 @@
1314
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1415

1516
/**
16-
* Order a collection using SQL ordering (not HQL ordering).
17-
*
18-
* Different from {@link jakarta.persistence.OrderBy} in that this expects SQL fragment, JPA OrderBy expects a
19-
* valid JPQL order-by fragment.
20-
*
21-
* @author Emmanuel Bernard
22-
* @author Steve Ebersole
17+
* Order a collection using an expression written in native SQL.
18+
* <p>
19+
* The order is applied by the database when the collection is fetched, but is not maintained
20+
* by operations that mutate the collection in memory. If the collection is a {@link java.util.Set}
21+
* or {@link java.util.Map}, the order is maintained using a {@link java.util.LinkedHashSet} or
22+
* {@link java.util.LinkedHashMap}.
23+
* <ul>
24+
* <li>Use {@link jakarta.persistence.OrderBy} to order using an expression written in HQL.
25+
* <li>Use {@link SortComparator} to sort the collection in memory using a {@link java.util.Comparator}.
26+
* <li>Use {@link SortNatural} to sort the collection in its {@link java.util.Comparator natural order}.
27+
* <li>Use {@link jakarta.persistence.OrderColumn} to maintain the order of a {@link java.util.List}
28+
* with a dedicated index column.
29+
* </ul>
30+
* <p>
31+
* It is illegal to use both {@code OrderBy} and {@link jakarta.persistence.OrderBy}.
2332
*
2433
* @see jakarta.persistence.OrderBy
2534
* @see SortComparator
2635
* @see SortNatural
36+
*
37+
* @author Emmanuel Bernard
38+
* @author Steve Ebersole
2739
*/
2840
@Target({METHOD, FIELD})
2941
@Retention(RUNTIME)
3042
public @interface OrderBy {
3143
/**
32-
* SQL ordering clause.
44+
* The native SQL expression used to sort the collection elements.
3345
*/
3446
String clause();
3547
}

hibernate-core/src/main/java/org/hibernate/annotations/SortComparator.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,29 @@
1515
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1616

1717
/**
18-
* Specifies in-memory Set/Map sorting using a specified {@link Comparator} for sorting.
18+
* Sort a {@link java.util.Set} or {@link java.util.Map} using the given {@link Comparator}.
19+
* <p>
20+
* Sorting is performed in memory, by Java's {@link java.util.TreeSet} or {@link java.util.TreeMap},
21+
* and is maintained by any operation that mutates the collection.
22+
* <ul>
23+
* <li>Use {@link SortNatural} in its {@link java.util.Comparator natural order}.
24+
* <li>Use {@link jakarta.persistence.OrderBy} to order using an expression written in HQL.
25+
* <li>Use {@link OrderBy} to order using an expression written in native SQL.
26+
* </ul>
27+
* <p>
28+
* It is illegal to use both {@code SortComparator} and {@link SortNatural}.
1929
*
20-
* NOTE : Sorting is different than ordering (see {@link OrderBy}) which is applied during the SQL SELECT.
21-
*
22-
* For sorting based on natural sort order, use {@link SortNatural} instead. It is illegal to combine
23-
* {@link SortComparator} and {@link SortNatural}.
24-
*
25-
* @see OrderBy
2630
* @see SortComparator
31+
* @see jakarta.persistence.OrderBy
32+
* @see OrderBy
2733
*
2834
* @author Steve Ebersole
2935
*/
3036
@Target({METHOD, FIELD})
3137
@Retention(RUNTIME)
3238
public @interface SortComparator {
3339
/**
34-
* Specifies the comparator class to use.
40+
* A class which implements {@link Comparator Comparator&lt;E&gt;} where {@code E} is the element type.
3541
*/
3642
Class<? extends Comparator<?>> value();
3743
}

hibernate-core/src/main/java/org/hibernate/annotations/SortNatural.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,21 @@
1414
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1515

1616
/**
17-
* Specifies in-memory Set/Map sorting using natural sorting.
17+
* Sort a {@link java.util.Set} or {@link java.util.Map} in its {@link Comparable natural order}
18+
* <p>
19+
* Sorting is performed in memory, by Java's {@link java.util.TreeSet} or {@link java.util.TreeMap},
20+
* and is maintained by any operation that mutates the collection.
21+
* <ul>
22+
* <li>Use {@link SortComparator} to sort the collection in memory using a {@link java.util.Comparator}.
23+
* <li>Use {@link jakarta.persistence.OrderBy} to order using an expression written in HQL.
24+
* <li>Use {@link OrderBy} to order using an expression written in native SQL.
25+
* </ul>
26+
* <p>
27+
* It is illegal to use both {@code SortNatural} and {@link SortComparator}.
1828
*
19-
* NOTE : Sorting is different than ordering (see {@link OrderBy}) which is applied during the SQL SELECT.
20-
*
21-
* For sorting based on a comparator, use {@link SortComparator} instead. It is illegal to combine
22-
*{@link SortComparator} and SortNatural.
23-
*
24-
* @see OrderBy
2529
* @see SortComparator
30+
* @see jakarta.persistence.OrderBy
31+
* @see OrderBy
2632
*
2733
* @author Steve Ebersole
2834
*/

0 commit comments

Comments
 (0)