diff --git a/documentation/src/main/asciidoc/userguide/appendices/Annotations.adoc b/documentation/src/main/asciidoc/userguide/appendices/Annotations.adoc index c5a69b3145..8041c6f7dc 100644 --- a/documentation/src/main/asciidoc/userguide/appendices/Annotations.adoc +++ b/documentation/src/main/asciidoc/userguide/appendices/Annotations.adoc @@ -1173,11 +1173,6 @@ The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibern See the <> section for more info on how `@SelectBeforeUpdate` works. -[[annotations-hibernate-sort]] -==== [line-through]#`@Sort`# - -The https://docs.jboss.org/hibernate/orm/{majorMinorVersion}/javadocs/org/hibernate/annotations/Sort.html[[line-through]#`@Sort`#] annotation is deprecated. Use the Hibernate specific <> or <> annotations instead. - [[annotations-hibernate-sortcomparator]] ==== `@SortComparator` diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/Sort.java b/hibernate-core/src/main/java/org/hibernate/annotations/Sort.java deleted file mode 100644 index 71d908724a..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/annotations/Sort.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -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; - -/** - * Collection sort (in-memory sorting). Different than ordering, which is applied during the SQL select. - * - * @author Emmanuel Bernard - * - * @see OrderBy - * - * @deprecated Use {@link SortComparator} or {@link SortNatural} instead depending on need. - */ -@Target({METHOD, FIELD}) -@Retention(RUNTIME) -@Deprecated -public @interface Sort { - /** - * The type of sorting to use. The default is to not use sorting. - */ - SortType type() default SortType.UNSORTED; - - /** - * Specifies the comparator to use. Only valid when {@link #type} specifies {@link SortType#COMPARATOR}. - * - * TODO find a way to use {@code Class} -> see HHH-8164 - */ - Class comparator() default void.class; -} diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/SortType.java b/hibernate-core/src/main/java/org/hibernate/annotations/SortType.java deleted file mode 100644 index 1e1b1507be..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/annotations/SortType.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.annotations; - -/** - * Possible collection sorting strategies. - * - * @author Emmanuel Bernard - * - * @deprecated Since {@link Sort} is deprecated. - */ -@Deprecated -public enum SortType { - /** - * The collection is unsorted. - */ - UNSORTED, - /** - * The collection is sorted using its natural sorting. - */ - NATURAL, - /** - * The collection is sorted using a supplied comparator. - */ - COMPARATOR -} diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java index 1d4531fcbc..fdc3d6a207 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java @@ -116,7 +116,6 @@ import org.hibernate.annotations.ParamDef; import org.hibernate.annotations.Parameter; import org.hibernate.annotations.Parent; import org.hibernate.annotations.Proxy; -import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortComparator; import org.hibernate.annotations.SortNatural; import org.hibernate.annotations.Source; @@ -2043,7 +2042,6 @@ public final class AnnotationBinder { collectionBinder.setJpaOrderBy( property.getAnnotation( javax.persistence.OrderBy.class ) ); collectionBinder.setSqlOrderBy( property.getAnnotation( OrderBy.class ) ); - collectionBinder.setSort( property.getAnnotation( Sort.class ) ); collectionBinder.setNaturalSort( property.getAnnotation( SortNatural.class ) ); collectionBinder.setComparatorSort( property.getAnnotation( SortComparator.class ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java index acb407af4c..0e0650f4be 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java @@ -60,10 +60,8 @@ import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDeleteAll; import org.hibernate.annotations.SQLInsert; import org.hibernate.annotations.SQLUpdate; -import org.hibernate.annotations.Sort; import org.hibernate.annotations.SortComparator; import org.hibernate.annotations.SortNatural; -import org.hibernate.annotations.SortType; import org.hibernate.annotations.Where; import org.hibernate.annotations.WhereJoinTable; import org.hibernate.annotations.common.reflection.XClass; @@ -170,7 +168,6 @@ public abstract class CollectionBinder { private boolean isSortedCollection; private javax.persistence.OrderBy jpaOrderBy; private OrderBy sqlOrderBy; - private Sort deprecatedSort; private SortNatural naturalSort; private SortComparator comparatorSort; @@ -247,10 +244,6 @@ public abstract class CollectionBinder { this.sqlOrderBy = sqlOrderBy; } - public void setSort(Sort deprecatedSort) { - this.deprecatedSort = deprecatedSort; - } - public void setNaturalSort(SortNatural naturalSort) { this.naturalSort = naturalSort; } @@ -623,21 +616,7 @@ public abstract class CollectionBinder { Class> comparatorClass = null; if ( jpaOrderBy == null && sqlOrderBy == null ) { - if ( deprecatedSort != null ) { - LOG.debug( "Encountered deprecated @Sort annotation; use @SortNatural or @SortComparator instead." ); - if ( naturalSort != null || comparatorSort != null ) { - throw buildIllegalSortCombination(); - } - hadExplicitSort = deprecatedSort.type() != SortType.UNSORTED; - if ( deprecatedSort.type() == SortType.NATURAL ) { - isSortedCollection = true; - } - else if ( deprecatedSort.type() == SortType.COMPARATOR ) { - isSortedCollection = true; - comparatorClass = deprecatedSort.comparator(); - } - } - else if ( naturalSort != null ) { + if ( naturalSort != null ) { if ( comparatorSort != null ) { throw buildIllegalSortCombination(); } @@ -692,7 +671,6 @@ public abstract class CollectionBinder { String.format( "Illegal combination of annotations on %s. Only one of @%s, @%s and @%s can be used", safeCollectionRole(), - Sort.class.getName(), SortNatural.class.getName(), SortComparator.class.getName() ) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java index 630fe1e5fe..229c79fa3c 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java @@ -11,7 +11,6 @@ import java.util.Map; import org.hibernate.AnnotationException; import org.hibernate.MappingException; import org.hibernate.annotations.OrderBy; -import org.hibernate.annotations.Sort; import org.hibernate.annotations.common.reflection.XClass; import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.boot.spi.MetadataBuildingContext; @@ -38,7 +37,7 @@ import org.jboss.logging.Logger; * @author Matthew Inger * @author Emmanuel Bernard */ -@SuppressWarnings({"unchecked", "serial"}) +@SuppressWarnings("unchecked") public class ListBinder extends CollectionBinder { private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, ListBinder.class.getName() ); @@ -58,13 +57,6 @@ public class ListBinder extends CollectionBinder { } } - @Override - public void setSort(Sort sortAnn) { - if ( sortAnn != null ) { - LOG.sortAnnotationIndexedCollection(); - } - } - @Override public SecondPass getSecondPass( final Ejb3JoinColumn[] fkJoinColumns, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/collectionelement/Matrix.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/collectionelement/Matrix.java index 4ca97a93b2..c008dbc528 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/collectionelement/Matrix.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/collectionelement/Matrix.java @@ -18,8 +18,7 @@ import javax.persistence.Id; import javax.persistence.MapKeyColumn; import org.hibernate.annotations.MapKeyType; -import org.hibernate.annotations.Sort; -import org.hibernate.annotations.SortType; +import org.hibernate.annotations.SortNatural; import org.hibernate.annotations.Type; /** @@ -34,7 +33,7 @@ public class Matrix { @MapKeyType( @Type(type="integer") ) @ElementCollection - @Sort(type = SortType.NATURAL) + @SortNatural @Type(type = "float") @MapKeyColumn(nullable = false) private SortedMap mvalues = new TreeMap(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/collections/SortNaturalByDefaultTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/collections/SortNaturalByDefaultTests.java index 49ad1ab388..c85d68cc8c 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/collections/SortNaturalByDefaultTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/metamodel/mapping/collections/SortNaturalByDefaultTests.java @@ -30,7 +30,6 @@ import static org.hamcrest.MatcherAssert.assertThat; *
    *
  • {@link org.hibernate.annotations.SortNatural @SortNatural}
  • *
  • {@link org.hibernate.annotations.SortComparator @SortComparator}
  • - *
  • {@link org.hibernate.annotations.Sort @Sort}
  • *
  • {@link org.hibernate.annotations.OrderBy @OrderBy(from hibernate)}
  • *
  • {@link javax.persistence.OrderBy @OrderBy(from JPA)}
  • *
diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/Customer.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/Customer.java index fbc7104c45..73894f91f4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/Customer.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/Customer.java @@ -20,8 +20,7 @@ import javax.persistence.OneToMany; import javax.persistence.OneToOne; import org.hibernate.annotations.Cascade; -import org.hibernate.annotations.Sort; -import org.hibernate.annotations.SortType; +import org.hibernate.annotations.SortComparator; import static org.hibernate.annotations.CascadeType.ALL; @@ -62,7 +61,7 @@ public class Customer implements Serializable { @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "CUST_ID") - @Sort(type = SortType.COMPARATOR, comparator = TicketComparator.class) + @SortComparator(TicketComparator.class) public SortedSet getTickets() { return tickets; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/indexcoll/Training.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/indexcoll/Training.java index 82aa00b30f..6355fe5c9d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/indexcoll/Training.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/indexcoll/Training.java @@ -15,8 +15,7 @@ import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.MapKey; -import org.hibernate.annotations.Sort; -import org.hibernate.annotations.SortType; +import org.hibernate.annotations.SortNatural; /** * @author Emmanuel Bernard @@ -24,7 +23,7 @@ import org.hibernate.annotations.SortType; @Entity public class Training { @Id @GeneratedValue private Long id; - @Sort(type= SortType.NATURAL) + @SortNatural @MapKey(name="name") @ManyToMany SortedMap trainees = new TreeMap(); public Long getId() { diff --git a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java index 987c8b2c48..9ac24b81a4 100644 --- a/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/envers/test/entities/manytomany/SortedSetEntity.java @@ -16,8 +16,7 @@ import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.MapKeyJoinColumn; -import org.hibernate.annotations.Sort; -import org.hibernate.annotations.SortType; +import org.hibernate.annotations.SortComparator; import org.hibernate.envers.Audited; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.envers.test.entities.StrTestEntityComparator; @@ -37,12 +36,12 @@ public class SortedSetEntity { @Audited @ManyToMany - @Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) + @SortComparator(StrTestEntityComparator.class) private SortedSet sortedSet = new TreeSet( StrTestEntityComparator.INSTANCE ); @Audited @ElementCollection @MapKeyJoinColumn - @Sort(type = SortType.COMPARATOR, comparator = StrTestEntityComparator.class) + @SortComparator(StrTestEntityComparator.class) private SortedMap sortedMap = new TreeMap( StrTestEntityComparator.INSTANCE ); public SortedSetEntity() { diff --git a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/sortedcollection/Printer.java b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/sortedcollection/Printer.java index 4d3baeb650..bdb00f6f25 100644 --- a/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/sortedcollection/Printer.java +++ b/tooling/metamodel-generator/src/test/java/org/hibernate/jpamodelgen/test/sortedcollection/Printer.java @@ -13,7 +13,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; -import org.hibernate.annotations.Sort; +import org.hibernate.annotations.SortNatural; /** * @author Hardy Ferentschik @@ -25,11 +25,11 @@ public class Printer { private long id; @OneToMany - @Sort + @SortNatural private SortedSet printQueue; @OneToMany - @Sort + @SortNatural private SortedMap printedJobs; }