HHH-18189 - Remove @IndexColumn
This commit is contained in:
parent
2dde0a7c46
commit
9e6d2e006d
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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 "";
|
||||
}
|
|
@ -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 )
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -319,10 +319,6 @@ public interface HibernateAnnotations {
|
|||
Imported.class,
|
||||
ImportedAnnotation.class
|
||||
);
|
||||
OrmAnnotationDescriptor<IndexColumn,IndexColumnAnnotation> INDEX_COLUMN = new OrmAnnotationDescriptor<>(
|
||||
IndexColumn.class,
|
||||
IndexColumnAnnotation.class
|
||||
);
|
||||
OrmAnnotationDescriptor<Instantiator,InstantiatorAnnotation> INSTANTIATOR = new OrmAnnotationDescriptor<>(
|
||||
Instantiator.class,
|
||||
InstantiatorAnnotation.class
|
||||
|
|
|
@ -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<? extends Annotation> 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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<Child> children = new ArrayList<>();
|
||||
|
||||
public int getId() {
|
||||
|
|
|
@ -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 "";
|
||||
}
|
||||
|
|
|
@ -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<String> strings;
|
||||
|
||||
public StringListEntity() {
|
||||
|
|
|
@ -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<IndexedListJoinColumnBidirectionalRefEdEntity> references;
|
||||
|
||||
|
|
|
@ -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<ParentOwnedIndexedListJoinColumnBidirectionalRefEdEntity> references;
|
||||
|
||||
|
|
Loading…
Reference in New Issue