diff --git a/documentation/src/main/asciidoc/userguide/chapters/domain/collections.adoc b/documentation/src/main/asciidoc/userguide/chapters/domain/collections.adoc index 5cc8263e10..59e0a5daa5 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/domain/collections.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/domain/collections.adoc @@ -156,7 +156,7 @@ after the collection is loaded, the collection would need to be refreshed to re- the elements. For this reason, ordered sets are not recommended - if the application needs ordering of the set elements, a sorted set should be preferred. For this reason, it is not covered in the User Guide. See the javadocs for `jakarta.persistence.OrderBy` -or `org.hibernate.annotations.OrderBy` for details. +or `org.hibernate.annotations.SQLOrder` for details. There are 2 options for sorting a set - naturally or using an explicit comparator. diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/DialectOverride.java b/hibernate-core/src/main/java/org/hibernate/annotations/DialectOverride.java index 6d9f0d54ca..b42fbd2267 100644 --- a/hibernate-core/src/main/java/org/hibernate/annotations/DialectOverride.java +++ b/hibernate-core/src/main/java/org/hibernate/annotations/DialectOverride.java @@ -90,33 +90,6 @@ public interface DialectOverride { Check[] value(); } - /** - * Specializes an {@link org.hibernate.annotations.OrderBy} - * in a certain dialect. - * - * @deprecated Use {@link SQLOrder} - */ - @Target({METHOD, FIELD}) - @Retention(RUNTIME) - @Repeatable(OrderBys.class) - @OverridesAnnotation(org.hibernate.annotations.OrderBy.class) - @Deprecated(since = "6.3", forRemoval = true) - @interface OrderBy { - /** - * The {@link Dialect} in which this override applies. - */ - Class extends Dialect> dialect(); - Version before() default @Version(major = MAX_VALUE); - Version sameOrAfter() default @Version(major = MIN_VALUE); - - org.hibernate.annotations.OrderBy override(); - } - @Target({METHOD, FIELD}) - @Retention(RUNTIME) - @interface OrderBys { - OrderBy[] value(); - } - /** * Specializes an {@link org.hibernate.annotations.SQLOrder} * in a certain dialect. diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/OrderBy.java b/hibernate-core/src/main/java/org/hibernate/annotations/OrderBy.java deleted file mode 100644 index 897f5ed2c7..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/annotations/OrderBy.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.annotations; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * 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 {@link java.util.Set} or {@link java.util.Map}, - * the order is maintained using a {@link java.util.LinkedHashSet} or - * {@link java.util.LinkedHashMap}. If the collection is a bag or - * {@link java.util.List}, the order is maintained by the underlying - * {@link java.util.ArrayList}. - *
- * There are several other ways to order or sort a collection: - *
- * It's illegal to use {@code OrderBy} together with the JPA-defined
- * {@link jakarta.persistence.OrderBy} for the same collection.
- *
- * @see jakarta.persistence.OrderBy
- * @see SortComparator
- * @see SortNatural
- *
- * @author Emmanuel Bernard
- * @author Steve Ebersole
- *
- * @see DialectOverride.OrderBy
- *
- * @deprecated Use {@link SQLOrder} instead. This annotation will be
- * removed eventually, since its unqualified name collides
- * with {@link jakarta.persistence.OrderBy}.
- */
-@Target({METHOD, FIELD})
-@Retention(RUNTIME)
-@Deprecated(since = "6.3", forRemoval = true)
-public @interface OrderBy {
- /**
- * The native SQL expression used to sort the collection elements.
- */
- String clause();
-}
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java
index bc88549c93..2ce729021b 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java
@@ -237,7 +237,6 @@ public abstract class CollectionBinder {
private boolean hibernateExtensionMapping;
private jakarta.persistence.OrderBy jpaOrderBy;
- private org.hibernate.annotations.OrderBy sqlOrderBy;
private SQLOrder sqlOrder;
private SortNatural naturalSort;
private SortComparator comparatorSort;
@@ -287,7 +286,6 @@ public abstract class CollectionBinder {
collectionBinder.setMapKey( property.getAnnotationUsage( MapKey.class, sourceModelContext ) );
collectionBinder.setPropertyName( inferredData.getPropertyName() );
collectionBinder.setJpaOrderBy( property.getAnnotationUsage( OrderBy.class, sourceModelContext ) );
- collectionBinder.setSqlOrderBy( getOverridableAnnotation( property, org.hibernate.annotations.OrderBy.class, context ) );
collectionBinder.setSqlOrder( getOverridableAnnotation( property, SQLOrder.class, context ) );
collectionBinder.setNaturalSort( property.getAnnotationUsage( SortNatural.class, sourceModelContext ) );
collectionBinder.setComparatorSort( property.getAnnotationUsage( SortComparator.class, sourceModelContext ) );
@@ -841,11 +839,6 @@ public abstract class CollectionBinder {
this.jpaOrderBy = jpaOrderBy;
}
- @SuppressWarnings("removal")
- public void setSqlOrderBy(org.hibernate.annotations.OrderBy sqlOrderBy) {
- this.sqlOrderBy = sqlOrderBy;
- }
-
public void setSqlOrder(SQLOrder sqlOrder) {
this.sqlOrder = sqlOrder;
}
@@ -1095,7 +1088,7 @@ public abstract class CollectionBinder {
}
if ( property.hasDirectAnnotationUsage( jakarta.persistence.OrderBy.class )
- || property.hasDirectAnnotationUsage( org.hibernate.annotations.OrderBy.class ) ) {
+ || property.hasDirectAnnotationUsage( org.hibernate.annotations.SQLOrder.class ) ) {
return CollectionClassification.BAG;
}
@@ -1443,15 +1436,12 @@ public abstract class CollectionBinder {
comparatorClass = null;
}
- if ( jpaOrderBy != null && ( sqlOrderBy != null || sqlOrder != null ) ) {
+ if ( jpaOrderBy != null && sqlOrder != null ) {
throw buildIllegalOrderCombination();
}
- boolean ordered = jpaOrderBy != null || sqlOrderBy != null || sqlOrder != null ;
+ final boolean ordered = jpaOrderBy != null || sqlOrder != null ;
if ( ordered ) {
// we can only apply the sql-based order by up front. The jpa order by has to wait for second pass
- if ( sqlOrderBy != null ) {
- collection.setOrderBy( sqlOrderBy.clause() );
- }
if ( sqlOrder != null ) {
collection.setOrderBy( sqlOrder.value() );
}
@@ -1490,7 +1480,7 @@ public abstract class CollectionBinder {
"Collection '%s' is annotated both '@%s' and '@%s'",
safeCollectionRole(),
jakarta.persistence.OrderBy.class.getName(),
- org.hibernate.annotations.OrderBy.class.getName()
+ org.hibernate.annotations.SQLOrder.class.getName()
)
);
}
@@ -1502,7 +1492,7 @@ public abstract class CollectionBinder {
"Collection '%s' is both sorted and ordered (only one of '@%s', '@%s', '@%s', and '@%s' may be used)",
safeCollectionRole(),
jakarta.persistence.OrderBy.class.getName(),
- org.hibernate.annotations.OrderBy.class.getName(),
+ org.hibernate.annotations.SQLOrder.class.getName(),
SortComparator.class.getName(),
SortNatural.class.getName()
)
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java
index 3785495682..7154104560 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ListBinder.java
@@ -7,9 +7,7 @@ package org.hibernate.boot.model.internal;
import java.util.Map;
import java.util.function.Supplier;
-import org.hibernate.AnnotationException;
import org.hibernate.MappingException;
-import org.hibernate.annotations.OrderBy;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.SecondPass;
import org.hibernate.mapping.Collection;
@@ -47,13 +45,6 @@ public class ListBinder extends CollectionBinder {
return new List( getCustomTypeBeanResolver(), owner, getBuildingContext() );
}
- @Override
- public void setSqlOrderBy(OrderBy orderByAnn) {
- if ( orderByAnn != null ) {
- throw new AnnotationException( "A collection of type 'List' is annotated '@OrderBy'" );
- }
- }
-
@Override
public SecondPass getSecondPass() {
return new CollectionSecondPass( ListBinder.this.collection ) {
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SetBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SetBinder.java
index cda391f885..1e380d6fbb 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SetBinder.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SetBinder.java
@@ -6,7 +6,6 @@ package org.hibernate.boot.model.internal;
import java.util.function.Supplier;
-import org.hibernate.annotations.OrderBy;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
@@ -34,10 +33,4 @@ public class SetBinder extends CollectionBinder {
return new Set( getCustomTypeBeanResolver(), persistentClass, getBuildingContext() );
}
- @Override
- public void setSqlOrderBy(OrderBy orderByAnn) {
- if ( orderByAnn != null ) {
- super.setSqlOrderBy( orderByAnn );
- }
- }
}
diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/DialectOverrideAnnotations.java b/hibernate-core/src/main/java/org/hibernate/boot/models/DialectOverrideAnnotations.java
index 4e8e82a72d..18f6b64350 100644
--- a/hibernate-core/src/main/java/org/hibernate/boot/models/DialectOverrideAnnotations.java
+++ b/hibernate-core/src/main/java/org/hibernate/boot/models/DialectOverrideAnnotations.java
@@ -27,8 +27,6 @@ import org.hibernate.boot.models.annotations.internal.OverriddenGeneratedColumnA
import org.hibernate.boot.models.annotations.internal.OverriddenGeneratedColumnsAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenJoinFormulaAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenJoinFormulasAnnotation;
-import org.hibernate.boot.models.annotations.internal.OverriddenOrderByAnnotation;
-import org.hibernate.boot.models.annotations.internal.OverriddenOrderBysAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenSQLDeleteAllAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenSQLDeleteAllsAnnotation;
import org.hibernate.boot.models.annotations.internal.OverriddenSQLDeleteAnnotation;
@@ -61,15 +59,6 @@ public interface DialectOverrideAnnotations {
OverriddenCheckAnnotation.class,
DIALECT_OVERRIDE_CHECKS
);
- OrmAnnotationDescriptor
*
*
diff --git a/migration-guide.adoc b/migration-guide.adoc
index 02aeed9660..a5eac6082d 100644
--- a/migration-guide.adoc
+++ b/migration-guide.adoc
@@ -429,15 +429,15 @@ In Hibernate 7, these SQL `UPDATE` statements only occur if the `@OrderColumn` i
** Removed `@SelectBeforeUpdate`
** Removed `@DynamicInsert#value` and `@DynamicUpdate#value`
** Removed `@Loader`
-** Removed `@Table`
-** Removed `@Where` and `@WhereJoinTable`
-** Removed `@ForeignKey`
-** Removed `@Index`
-** Removed `@IndexColumn`
+** Removed `@Table` -> use JPA `@Table`
+** Removed `@Where` and `@WhereJoinTable` -> use `@SQLRestriction` or `@SQLJoinTableRestriction`
+** Removed `@OrderBy` -> use `@SQLOrder` or JPA `@OrderBy`
+** Removed `@ForeignKey` -> use JPA `@ForeignKey`
+** Removed `@Index` -> use JPA `@Index`
+** Removed `@IndexColumn` -> use JPA `@OrderColumn`
** Removed `@GeneratorType` (and `GenerationTime`, etc)
** Removed `@LazyToOne`
** Removed `@LazyCollection`
-** Removed `@IndexColumn`
** Replaced uses of `CacheModeType` with `CacheMode`
** Removed `@TestForIssue` (for testing purposes) -> use `org.hibernate.testing.orm.junit.JiraKey` and `org.hibernate.testing.orm.junit.JiraKeyGroup`