From 9e6d2e006d4321e7b16aaf981fd7a29fb3512f7b Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 23 Jul 2024 16:49:04 -0500 Subject: [PATCH] HHH-18189 - Remove @IndexColumn --- .../hibernate/annotations/IndexColumn.java | 47 -------- .../boot/model/internal/CollectionBinder.java | 2 - .../boot/model/internal/IndexColumn.java | 48 -------- .../boot/models/HibernateAnnotations.java | 4 - .../internal/IndexColumnAnnotation.java | 106 ------------------ ...nidirectionalOneToManyIndexColumnTest.java | 21 ++-- .../org/hibernate/envers/AuditMappedBy.java | 5 +- .../entities/collection/StringListEntity.java | 9 +- ...stJoinColumnBidirectionalRefIngEntity.java | 11 +- ...stJoinColumnBidirectionalRefIngEntity.java | 13 ++- 10 files changed, 31 insertions(+), 235 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/annotations/IndexColumn.java delete mode 100644 hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexColumnAnnotation.java diff --git a/hibernate-core/src/main/java/org/hibernate/annotations/IndexColumn.java b/hibernate-core/src/main/java/org/hibernate/annotations/IndexColumn.java deleted file mode 100644 index e5d57571f9..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/annotations/IndexColumn.java +++ /dev/null @@ -1,47 +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; - -/** - * Describe an index column of a List. - * - * @author Matthew Inger - * - * @deprecated Prefer the standard JPA {@link jakarta.persistence.OrderColumn} annotation, - * using {@link ListIndexBase} instead of {@link #base()}. - */ -@Target({METHOD, FIELD}) -@Retention(RUNTIME) -@Deprecated -public @interface IndexColumn { - /** - * The column name. - */ - String name(); - - /** - * The starting index value. Zero (0) by default, since Lists indexes start at zero (0). - */ - int base() default 0; - - /** - * Is the column nullable? - */ - boolean nullable() default true; - - /** - * An explicit column definition. - */ - String columnDefinition() default ""; -} 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 7ed5ba0a6a..da0998010a 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 @@ -474,7 +474,6 @@ public abstract class CollectionBinder { MemberDetails property) { return IndexColumn.fromAnnotations( property.getDirectAnnotationUsage( OrderColumn.class ), - property.getDirectAnnotationUsage( org.hibernate.annotations.IndexColumn.class ), property.getDirectAnnotationUsage( ListIndexBase.class ), propertyHolder, inferredData, @@ -1074,7 +1073,6 @@ public abstract class CollectionBinder { if ( java.util.List.class.isAssignableFrom( semanticJavaType ) ) { if ( property.hasDirectAnnotationUsage( OrderColumn.class ) - || property.hasDirectAnnotationUsage( org.hibernate.annotations.IndexColumn.class ) || property.hasDirectAnnotationUsage( ListIndexBase.class ) || property.hasDirectAnnotationUsage( ListIndexJdbcType.class ) || property.hasDirectAnnotationUsage( ListIndexJdbcTypeCode.class ) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java index db08735cca..14988d690f 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java @@ -33,7 +33,6 @@ public class IndexColumn extends AnnotatedColumn { public static IndexColumn fromAnnotations( OrderColumn orderColumn, - org.hibernate.annotations.IndexColumn indexColumn, ListIndexBase listIndexBase, PropertyHolder propertyHolder, PropertyData inferredData, @@ -43,10 +42,6 @@ public class IndexColumn extends AnnotatedColumn { if ( orderColumn != null ) { column = buildColumnFromOrderColumn( orderColumn, propertyHolder, inferredData, secondaryTables, context ); } - else if ( indexColumn != null ) { - column = buildColumnFromIndexColumn( indexColumn, propertyHolder, inferredData, context ); - column.setBase( indexColumn.base() ); - } else { column = new IndexColumn(); column.setLogicalColumnName( inferredData.getPropertyName() + "_ORDER" ); //JPA default name @@ -130,47 +125,4 @@ public class IndexColumn extends AnnotatedColumn { return column; } } - - /** - * Legacy {@link IndexColumn @IndexColumn} processing. - * - * @param indexColumn The IndexColumn annotation instance - * @param propertyHolder Information about the property - * @param inferredData Yeah, right. Uh... - * - * @return The index column - */ - public static IndexColumn buildColumnFromIndexColumn( - org.hibernate.annotations.IndexColumn indexColumn, - PropertyHolder propertyHolder, - PropertyData inferredData, - MetadataBuildingContext context) { - if ( indexColumn != null ) { - final String explicitName = indexColumn.name(); - final String name = explicitName.isEmpty() - ? inferredData.getPropertyName() - : explicitName; - final String sqlType = nullIfEmpty( indexColumn.columnDefinition() ); - //TODO move it to a getter based system and remove the constructor - final IndexColumn column = new IndexColumn(); - column.setLogicalColumnName( name ); - column.setSqlType( sqlType ); - column.setNullable( indexColumn.nullable() ); - column.setBase( indexColumn.base() ); -// column.setContext( context ); -// column.setPropertyHolder( propertyHolder ); - createParent( propertyHolder, null, column, context ); - column.bind(); - return column; - } - else { - final IndexColumn column = new IndexColumn(); - column.setImplicit( true ); -// column.setContext( context ); -// column.setPropertyHolder( propertyHolder ); - createParent( propertyHolder, null, column, context ); - column.bind(); - return column; - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java b/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java index 991506a19c..3ac7b0a826 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/models/HibernateAnnotations.java @@ -319,10 +319,6 @@ public interface HibernateAnnotations { Imported.class, ImportedAnnotation.class ); - OrmAnnotationDescriptor INDEX_COLUMN = new OrmAnnotationDescriptor<>( - IndexColumn.class, - IndexColumnAnnotation.class - ); OrmAnnotationDescriptor INSTANTIATOR = new OrmAnnotationDescriptor<>( Instantiator.class, InstantiatorAnnotation.class diff --git a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexColumnAnnotation.java b/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexColumnAnnotation.java deleted file mode 100644 index 556939d1a8..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/boot/models/annotations/internal/IndexColumnAnnotation.java +++ /dev/null @@ -1,106 +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 http://www.gnu.org/licenses/lgpl-2.1.html. - */ -package org.hibernate.boot.models.annotations.internal; - -import java.lang.annotation.Annotation; - -import org.hibernate.annotations.IndexColumn; -import org.hibernate.boot.models.HibernateAnnotations; -import org.hibernate.models.spi.SourceModelBuildingContext; - -import org.jboss.jandex.AnnotationInstance; - -import static org.hibernate.boot.models.internal.OrmAnnotationHelper.extractJandexValue; - -@SuppressWarnings({ "ClassExplicitlyAnnotation", "unused" }) -@jakarta.annotation.Generated("org.hibernate.orm.build.annotations.ClassGeneratorProcessor") -public class IndexColumnAnnotation implements IndexColumn { - private String name; - private int base; - private boolean nullable; - private String columnDefinition; - - /** - * Used in creating dynamic annotation instances (e.g. from XML) - */ - public IndexColumnAnnotation(SourceModelBuildingContext modelContext) { - this.base = 0; - this.nullable = true; - this.columnDefinition = ""; - } - - /** - * Used in creating annotation instances from JDK variant - */ - public IndexColumnAnnotation(IndexColumn annotation, SourceModelBuildingContext modelContext) { - this.name = annotation.name(); - this.base = annotation.base(); - this.nullable = annotation.nullable(); - this.columnDefinition = annotation.columnDefinition(); - } - - /** - * Used in creating annotation instances from Jandex variant - */ - public IndexColumnAnnotation(AnnotationInstance annotation, SourceModelBuildingContext modelContext) { - this.name = extractJandexValue( annotation, HibernateAnnotations.INDEX_COLUMN, "name", modelContext ); - this.base = extractJandexValue( annotation, HibernateAnnotations.INDEX_COLUMN, "base", modelContext ); - this.nullable = extractJandexValue( annotation, HibernateAnnotations.INDEX_COLUMN, "nullable", modelContext ); - this.columnDefinition = extractJandexValue( - annotation, - HibernateAnnotations.INDEX_COLUMN, - "columnDefinition", - modelContext - ); - } - - @Override - public Class annotationType() { - return IndexColumn.class; - } - - @Override - public String name() { - return name; - } - - public void name(String value) { - this.name = value; - } - - - @Override - public int base() { - return base; - } - - public void base(int value) { - this.base = value; - } - - - @Override - public boolean nullable() { - return nullable; - } - - public void nullable(boolean value) { - this.nullable = value; - } - - - @Override - public String columnDefinition() { - return columnDefinition; - } - - public void columnDefinition(String value) { - this.columnDefinition = value; - } - - -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyIndexColumnTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyIndexColumnTest.java index 9f52d21b53..34cb73af0e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyIndexColumnTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyIndexColumnTest.java @@ -8,30 +8,31 @@ package org.hibernate.orm.test.jpa.mapping; import java.util.ArrayList; import java.util.List; -import jakarta.persistence.CascadeType; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; -import jakarta.persistence.Table; -import org.hibernate.annotations.IndexColumn; import org.hibernate.cfg.AvailableSettings; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.Jpa; import org.hibernate.testing.orm.junit.Setting; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import static org.hamcrest.core.Is.is; +import jakarta.persistence.CascadeType; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderColumn; +import jakarta.persistence.Table; + import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; /** * @author Andrea Boriero */ +@SuppressWarnings("JUnitMalformedDeclaration") @JiraKey( value = "HHH-1268") @Jpa( annotatedClasses = { @@ -96,7 +97,7 @@ public class UnidirectionalOneToManyIndexColumnTest { private int id; @OneToMany(targetEntity = Child.class, cascade = CascadeType.ALL) - @IndexColumn(name = "position") + @OrderColumn(name = "position") private List children = new ArrayList<>(); public int getId() { diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/AuditMappedBy.java b/hibernate-envers/src/main/java/org/hibernate/envers/AuditMappedBy.java index 03d6625a85..7929d090f3 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/AuditMappedBy.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/AuditMappedBy.java @@ -35,9 +35,8 @@ public @interface AuditMappedBy { /** * Name of the property in the related entity which maps to the position column. Should be specified only - * for indexed collection, when @{@link org.hibernate.annotations.IndexColumn} or - * {@link jakarta.persistence.OrderColumn} is used on the collection. The property should be mapped with - * {@code @Column(insertable=false, updatable=false)}. + * for indexed collection, when {@link jakarta.persistence.OrderColumn} is used on the collection. The + * property should be mapped with {@code @Column(insertable=false, updatable=false)}. */ String positionMappedBy() default ""; } diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/collection/StringListEntity.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/collection/StringListEntity.java index 76e48e25da..289c5e9ca3 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/collection/StringListEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/collection/StringListEntity.java @@ -8,13 +8,14 @@ package org.hibernate.orm.test.envers.entities.collection; import java.util.ArrayList; import java.util.List; + +import org.hibernate.envers.Audited; + import jakarta.persistence.ElementCollection; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; - -import org.hibernate.annotations.IndexColumn; -import org.hibernate.envers.Audited; +import jakarta.persistence.OrderColumn; /** * @author Adam Warski (adam at warski dot org) @@ -27,7 +28,7 @@ public class StringListEntity { @Audited @ElementCollection - @IndexColumn(name = "list_index") + @OrderColumn(name = "list_index") private List strings; public StringListEntity() { diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java index 43bd306811..8ccc6eebb6 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/detached/IndexedListJoinColumnBidirectionalRefIngEntity.java @@ -9,17 +9,18 @@ package org.hibernate.orm.test.envers.entities.onetomany.detached; import java.util.ArrayList; import java.util.Arrays; import java.util.List; + +import org.hibernate.envers.AuditMappedBy; +import org.hibernate.envers.Audited; + import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderColumn; import jakarta.persistence.Table; -import org.hibernate.annotations.IndexColumn; -import org.hibernate.envers.AuditMappedBy; -import org.hibernate.envers.Audited; - /** * Entity for {@link org.hibernate.orm.test.envers.integration.onetomany.detached.IndexedJoinColumnBidirectionalList} test. * Owning side of the relation. @@ -38,7 +39,7 @@ public class IndexedListJoinColumnBidirectionalRefIngEntity { @OneToMany @JoinColumn(name = "indexed_join_column") - @IndexColumn(name = "indexed_index") + @OrderColumn(name = "indexed_index") @AuditMappedBy(mappedBy = "owner", positionMappedBy = "position") private List references; diff --git a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java index 5ee083d70a..c1583c3716 100644 --- a/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java +++ b/hibernate-envers/src/test/java/org/hibernate/orm/test/envers/entities/onetomany/detached/inheritance/ParentIndexedListJoinColumnBidirectionalRefIngEntity.java @@ -9,6 +9,11 @@ package org.hibernate.orm.test.envers.entities.onetomany.detached.inheritance; import java.util.ArrayList; import java.util.Arrays; import java.util.List; + +import org.hibernate.envers.AuditMappedBy; +import org.hibernate.envers.Audited; +import org.hibernate.orm.test.envers.integration.onetomany.detached.InheritanceIndexedJoinColumnBidirectionalList; + import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; @@ -16,13 +21,9 @@ import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import jakarta.persistence.OrderColumn; import jakarta.persistence.Table; -import org.hibernate.annotations.IndexColumn; -import org.hibernate.envers.AuditMappedBy; -import org.hibernate.envers.Audited; -import org.hibernate.orm.test.envers.integration.onetomany.detached.InheritanceIndexedJoinColumnBidirectionalList; - /** * Entity for {@link InheritanceIndexedJoinColumnBidirectionalList} test. * Parent, owning side of the relation. @@ -42,7 +43,7 @@ public abstract class ParentIndexedListJoinColumnBidirectionalRefIngEntity { @OneToMany @JoinColumn(name = "indexed_join_column") - @IndexColumn(name = "indexed_index") + @OrderColumn(name = "indexed_index") @AuditMappedBy(mappedBy = "owner", positionMappedBy = "position") private List references;