HHH-15960 reimplement @Column using the o.h.binder infrastructure and add @Comment(on ="...")

this lets me deprecate @Table(comment = "...") and gets rid of all the passing-Comment-objects-around
This commit is contained in:
Gavin 2023-01-01 19:42:28 +01:00 committed by Gavin King
parent df5980226c
commit a1853a8c05
16 changed files with 200 additions and 108 deletions

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.annotations; package org.hibernate.annotations;
import org.hibernate.binder.internal.CommentBinder;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.Target; import java.lang.annotation.Target;
@ -16,18 +18,31 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/** /**
* Specifies a comment that will be included in generated DDL. * Specifies a comment that will be included in generated DDL.
* <p>
* By default, if {@link #on} is <em>not</em> specified:
* <ul> * <ul>
* <li>When a field or property is annotated, the comment applies to the mapped column. * <li>when a field or property is annotated, the comment applies to the mapped column,
* <li>When an entity class is annotated, the comment applies to the primary table. * <li>when a collection is annotated, the comment applies to the collection table, and
* <li>when an entity class is annotated, the comment applies to the primary table.
* </ul> * </ul>
* <p>
* But when {@link #on} is explicitly specified, the comment applies to the mapped table
* or column with the specified name.
* *
* @author Yanming Zhou * @author Yanming Zhou
*/ */
@TypeBinderType(binder = CommentBinder.class)
@AttributeBinderType(binder = CommentBinder.class)
@Target({METHOD, FIELD, TYPE}) @Target({METHOD, FIELD, TYPE})
@Retention(RUNTIME) @Retention(RUNTIME)
public @interface Comment { public @interface Comment {
/** /**
* The comment string. * The text of the comment.
*/ */
String value(); String value();
/**
* The name of the table or column to add the comment to.
*/
String on() default "";
} }

View File

@ -9,8 +9,6 @@ package org.hibernate.annotations;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.hibernate.Remove;
import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.ElementType.TYPE;
@ -24,7 +22,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({FIELD, METHOD, TYPE}) @Target({FIELD, METHOD, TYPE})
@Retention(RUNTIME) @Retention(RUNTIME)
@Deprecated( forRemoval = true ) @Deprecated( forRemoval = true )
@Remove( )
public @interface ForeignKey { public @interface ForeignKey {
/** /**
* Name of the foreign key of a {@code OneToMany}, {@code ManyToOne}, or * Name of the foreign key of a {@code OneToMany}, {@code ManyToOne}, or

View File

@ -52,11 +52,10 @@ public @interface Table {
/** /**
* Specifies comment to add to the generated DDL for the table. * Specifies comment to add to the generated DDL for the table.
* <p>
* <em>Useful for secondary tables, otherwise use {@link Comment}.</em>
* *
* @see Comment * @deprecated use {@link Comment}
*/ */
@Deprecated(since = "6.2")
String comment() default ""; String comment() default "";
/** /**
@ -64,7 +63,7 @@ public @interface Table {
* *
* @deprecated use {@link jakarta.persistence.SecondaryTable#foreignKey()} * @deprecated use {@link jakarta.persistence.SecondaryTable#foreignKey()}
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0", forRemoval = true)
ForeignKey foreignKey() default @ForeignKey(name = ""); ForeignKey foreignKey() default @ForeignKey(name = "");
/** /**

View File

@ -0,0 +1,87 @@
/*
* 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.binder.internal;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.Comment;
import org.hibernate.binder.AttributeBinder;
import org.hibernate.binder.TypeBinder;
import org.hibernate.boot.spi.MetadataBuildingContext;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.Value;
/**
* Handles {@link Comment} annotations.
*
* @author Gavin King
*/
public class CommentBinder implements AttributeBinder<Comment>, TypeBinder<Comment> {
@Override
public void bind(Comment comment, MetadataBuildingContext context, PersistentClass entity, Property property) {
String text = comment.value();
String on = comment.on();
Value value = property.getValue();
if ( value instanceof OneToMany ) {
throw new AnnotationException( "One to many association '" + property.getName()
+ "' was annotated '@Comment'");
}
else if ( value instanceof Collection ) {
Collection collection = (Collection) value;
Table table = collection.getTable();
// by default, the comment goes on the table
if ( on.isEmpty() || table.getName().equalsIgnoreCase( on ) ) {
table.setComment( text );
}
// but if 'on' is explicit, it can go on a column
Value element = collection.getElement();
for ( Column column : element.getColumns() ) {
if ( column.getName().equalsIgnoreCase( on ) ) {
column.setComment( text );
}
}
//TODO: list index / map key columns
}
else {
for ( Column column : value.getColumns() ) {
if ( on.isEmpty() || column.getName().equalsIgnoreCase( on ) ) {
column.setComment( text );
}
}
}
}
@Override
public void bind(Comment comment, MetadataBuildingContext context, PersistentClass entity) {
String text = comment.value();
String on = comment.on();
Table primary = entity.getTable();
// by default, the comment goes on the primary table
if ( on.isEmpty() || primary.getName().equalsIgnoreCase( on ) ) {
primary.setComment( text );
}
// but if 'on' is explicit, it can go on a secondary table
for ( Join join : entity.getJoins() ) {
Table secondary = join.getTable();
if ( secondary.getName().equalsIgnoreCase( on ) ) {
secondary.setComment( text );
}
}
}
@Override
public void bind(Comment comment, MetadataBuildingContext context, Component embeddable) {
throw new AnnotationException( "Embeddable class '" + embeddable.getComponentClassName()
+ "' was annotated '@Comment' (annotate its attributes instead)" );
}
}

View File

@ -8,5 +8,8 @@
/** /**
* Built-in implementations of {@link org.hibernate.binder.AttributeBinder} * Built-in implementations of {@link org.hibernate.binder.AttributeBinder}
* and {@link org.hibernate.binder.TypeBinder}. * and {@link org.hibernate.binder.TypeBinder}.
*
* @implNote Implementing built-in annotations here helps clean up the messy
* code in {@link org.hibernate.boot.model.internal}.
*/ */
package org.hibernate.binder.internal; package org.hibernate.binder.internal;

View File

@ -21,6 +21,7 @@
* with a user-written annotation which targets * with a user-written annotation which targets
* {@linkplain java.lang.annotation.ElementType#FIELD fields} and * {@linkplain java.lang.annotation.ElementType#FIELD fields} and
* properties of entity types and embeddable classes. * properties of entity types and embeddable classes.
* </ul>
* *
* @see org.hibernate.binder.AttributeBinder * @see org.hibernate.binder.AttributeBinder
* @see org.hibernate.binder.TypeBinder * @see org.hibernate.binder.TypeBinder

View File

@ -14,7 +14,6 @@ import org.hibernate.annotations.Check;
import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.ColumnTransformer; import org.hibernate.annotations.ColumnTransformer;
import org.hibernate.annotations.ColumnTransformers; import org.hibernate.annotations.ColumnTransformers;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.GeneratedColumn; import org.hibernate.annotations.GeneratedColumn;
import org.hibernate.annotations.Index; import org.hibernate.annotations.Index;
import org.hibernate.annotations.common.reflection.XProperty; import org.hibernate.annotations.common.reflection.XProperty;
@ -84,7 +83,7 @@ public class AnnotatedColumn {
private String defaultValue; private String defaultValue;
private String generatedAs; private String generatedAs;
private String comment; // private String comment;
private String checkConstraint; private String checkConstraint;
private AnnotatedColumns parent; private AnnotatedColumns parent;
@ -202,13 +201,13 @@ public class AnnotatedColumn {
this.checkConstraint = checkConstraint; this.checkConstraint = checkConstraint;
} }
public String getComment() { // public String getComment() {
return comment; // return comment;
} // }
public void setComment(String comment) { // public void setComment(String comment) {
this.comment = comment; // this.comment = comment;
} // }
public String getGeneratedAs() { public String getGeneratedAs() {
return generatedAs; return generatedAs;
@ -245,9 +244,9 @@ public class AnnotatedColumn {
if ( checkConstraint !=null ) { if ( checkConstraint !=null ) {
mappingColumn.setCheckConstraint( checkConstraint ); mappingColumn.setCheckConstraint( checkConstraint );
} }
if ( isNotEmpty( comment ) ) { // if ( isNotEmpty( comment ) ) {
mappingColumn.setComment( comment ); // mappingColumn.setComment( comment );
} // }
if ( generatedAs != null ) { if ( generatedAs != null ) {
mappingColumn.setGeneratedAs( generatedAs ); mappingColumn.setGeneratedAs( generatedAs );
} }
@ -471,7 +470,7 @@ public class AnnotatedColumn {
public static AnnotatedColumns buildFormulaFromAnnotation( public static AnnotatedColumns buildFormulaFromAnnotation(
org.hibernate.annotations.Formula formulaAnn, org.hibernate.annotations.Formula formulaAnn,
Comment commentAnn, // Comment commentAnn,
Nullability nullability, Nullability nullability,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
@ -480,7 +479,7 @@ public class AnnotatedColumn {
return buildColumnOrFormulaFromAnnotation( return buildColumnOrFormulaFromAnnotation(
null, null,
formulaAnn, formulaAnn,
commentAnn, // commentAnn,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -490,7 +489,7 @@ public class AnnotatedColumn {
} }
public static AnnotatedColumns buildColumnFromNoAnnotation( public static AnnotatedColumns buildColumnFromNoAnnotation(
Comment commentAnn, // Comment commentAnn,
Nullability nullability, Nullability nullability,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
@ -498,7 +497,7 @@ public class AnnotatedColumn {
MetadataBuildingContext context) { MetadataBuildingContext context) {
return buildColumnsFromAnnotations( return buildColumnsFromAnnotations(
null, null,
commentAnn, // commentAnn,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -509,7 +508,7 @@ public class AnnotatedColumn {
public static AnnotatedColumns buildColumnFromAnnotation( public static AnnotatedColumns buildColumnFromAnnotation(
jakarta.persistence.Column column, jakarta.persistence.Column column,
Comment commentAnn, // Comment commentAnn,
Nullability nullability, Nullability nullability,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
@ -518,7 +517,7 @@ public class AnnotatedColumn {
return buildColumnOrFormulaFromAnnotation( return buildColumnOrFormulaFromAnnotation(
column, column,
null, null,
commentAnn, // commentAnn,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -529,7 +528,7 @@ public class AnnotatedColumn {
public static AnnotatedColumns buildColumnsFromAnnotations( public static AnnotatedColumns buildColumnsFromAnnotations(
jakarta.persistence.Column[] columns, jakarta.persistence.Column[] columns,
Comment commentAnn, // Comment commentAnn,
Nullability nullability, Nullability nullability,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
@ -538,7 +537,7 @@ public class AnnotatedColumn {
return buildColumnsOrFormulaFromAnnotation( return buildColumnsOrFormulaFromAnnotation(
columns, columns,
null, null,
commentAnn, // commentAnn,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -550,7 +549,7 @@ public class AnnotatedColumn {
public static AnnotatedColumns buildColumnsFromAnnotations( public static AnnotatedColumns buildColumnsFromAnnotations(
jakarta.persistence.Column[] columns, jakarta.persistence.Column[] columns,
Comment commentAnn, // Comment commentAnn,
Nullability nullability, Nullability nullability,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
@ -560,7 +559,7 @@ public class AnnotatedColumn {
return buildColumnsOrFormulaFromAnnotation( return buildColumnsOrFormulaFromAnnotation(
columns, columns,
null, null,
commentAnn, // commentAnn,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -573,7 +572,7 @@ public class AnnotatedColumn {
public static AnnotatedColumns buildColumnOrFormulaFromAnnotation( public static AnnotatedColumns buildColumnOrFormulaFromAnnotation(
jakarta.persistence.Column column, jakarta.persistence.Column column,
org.hibernate.annotations.Formula formulaAnn, org.hibernate.annotations.Formula formulaAnn,
Comment commentAnn, // Comment commentAnn,
Nullability nullability, Nullability nullability,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
@ -582,7 +581,7 @@ public class AnnotatedColumn {
return buildColumnsOrFormulaFromAnnotation( return buildColumnsOrFormulaFromAnnotation(
new jakarta.persistence.Column[] { column }, new jakarta.persistence.Column[] { column },
formulaAnn, formulaAnn,
commentAnn, // commentAnn,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -595,7 +594,7 @@ public class AnnotatedColumn {
public static AnnotatedColumns buildColumnsOrFormulaFromAnnotation( public static AnnotatedColumns buildColumnsOrFormulaFromAnnotation(
jakarta.persistence.Column[] columns, jakarta.persistence.Column[] columns,
org.hibernate.annotations.Formula formulaAnn, org.hibernate.annotations.Formula formulaAnn,
Comment comment, // Comment comment,
Nullability nullability, Nullability nullability,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
@ -626,14 +625,14 @@ public class AnnotatedColumn {
suffixForDefaultColumnName, suffixForDefaultColumnName,
secondaryTables, secondaryTables,
propertyHolder, propertyHolder,
comment, // comment,
nullability, nullability,
context context
); );
} }
else { else {
return buildExplicitColumns( return buildExplicitColumns(
comment, // comment,
propertyHolder, propertyHolder,
inferredData, inferredData,
suffixForDefaultColumnName, suffixForDefaultColumnName,
@ -670,7 +669,7 @@ public class AnnotatedColumn {
} }
private static AnnotatedColumns buildExplicitColumns( private static AnnotatedColumns buildExplicitColumns(
Comment comment, // Comment comment,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
String suffixForDefaultColumnName, String suffixForDefaultColumnName,
@ -692,7 +691,7 @@ public class AnnotatedColumn {
// final Identifier physicalName = physicalNamingStrategy.toPhysicalTableName( logicalName ); // final Identifier physicalName = physicalNamingStrategy.toPhysicalTableName( logicalName );
// tableName = physicalName.render( database.getDialect() ); // tableName = physicalName.render( database.getDialect() );
buildColumn( buildColumn(
comment, // comment,
propertyHolder, propertyHolder,
inferredData, inferredData,
suffixForDefaultColumnName, suffixForDefaultColumnName,
@ -718,7 +717,7 @@ public class AnnotatedColumn {
} }
private static AnnotatedColumn buildColumn( private static AnnotatedColumn buildColumn(
Comment comment, // Comment comment,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
PropertyData inferredData, PropertyData inferredData,
String suffixForDefaultColumnName, String suffixForDefaultColumnName,
@ -739,9 +738,9 @@ public class AnnotatedColumn {
// annotatedColumn.setPropertyHolder( propertyHolder ); // annotatedColumn.setPropertyHolder( propertyHolder );
// annotatedColumn.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) ); // annotatedColumn.setPropertyName( getRelativePath( propertyHolder, inferredData.getPropertyName() ) );
annotatedColumn.setNullable( column.nullable() ); //TODO force to not null if available? This is a (bad) user choice. annotatedColumn.setNullable( column.nullable() ); //TODO force to not null if available? This is a (bad) user choice.
if ( comment != null ) { // if ( comment != null ) {
annotatedColumn.setComment( comment.value() ); // annotatedColumn.setComment( comment.value() );
} // }
annotatedColumn.setUnique( column.unique() ); annotatedColumn.setUnique( column.unique() );
annotatedColumn.setInsertable( column.insertable() ); annotatedColumn.setInsertable( column.insertable() );
annotatedColumn.setUpdatable( column.updatable() ); annotatedColumn.setUpdatable( column.updatable() );
@ -859,7 +858,7 @@ public class AnnotatedColumn {
String suffixForDefaultColumnName, String suffixForDefaultColumnName,
Map<String, Join> secondaryTables, Map<String, Join> secondaryTables,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
Comment comment, // Comment comment,
Nullability nullability, Nullability nullability,
MetadataBuildingContext context) { MetadataBuildingContext context) {
final AnnotatedColumns columns = new AnnotatedColumns(); final AnnotatedColumns columns = new AnnotatedColumns();
@ -869,9 +868,9 @@ public class AnnotatedColumn {
columns.setJoins( secondaryTables ); columns.setJoins( secondaryTables );
columns.setPropertyHolder( propertyHolder ); columns.setPropertyHolder( propertyHolder );
final AnnotatedColumn column = new AnnotatedColumn(); final AnnotatedColumn column = new AnnotatedColumn();
if ( comment != null ) { // if ( comment != null ) {
column.setComment( comment.value() ); // column.setComment( comment.value() );
} // }
//not following the spec but more clean //not following the spec but more clean
if ( nullability != Nullability.FORCED_NULL if ( nullability != Nullability.FORCED_NULL
&& inferredData.getClassOrElement().isPrimitive() && inferredData.getClassOrElement().isPrimitive()

View File

@ -8,7 +8,6 @@ package org.hibernate.boot.model.internal;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.JoinFormula; import org.hibernate.annotations.JoinFormula;
import org.hibernate.boot.model.naming.Identifier; import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.ObjectNameNormalizer; import org.hibernate.boot.model.naming.ObjectNameNormalizer;
@ -84,7 +83,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
throw new AnnotationException( "Property '" + path throw new AnnotationException( "Property '" + path
+ "' overrides mapping specified using '@JoinColumnOrFormula'" ); + "' overrides mapping specified using '@JoinColumnOrFormula'" );
} }
return buildJoinColumn( joinColumn, null, mappedBy, parent, propertyHolder, inferredData, "" ); return buildJoinColumn( joinColumn, /*null,*/ mappedBy, parent, propertyHolder, inferredData, "" );
} }
public static AnnotatedJoinColumn buildJoinFormula( public static AnnotatedJoinColumn buildJoinFormula(
@ -104,7 +103,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
static AnnotatedJoinColumn buildJoinColumn( static AnnotatedJoinColumn buildJoinColumn(
JoinColumn joinColumn, JoinColumn joinColumn,
Comment comment, // Comment comment,
String mappedBy, String mappedBy,
AnnotatedJoinColumns parent, AnnotatedJoinColumns parent,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
@ -116,7 +115,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
+ getRelativePath( propertyHolder, inferredData.getPropertyName() ) + getRelativePath( propertyHolder, inferredData.getPropertyName() )
+ "' is 'mappedBy' a different entity and may not explicitly specify the '@JoinColumn'" ); + "' is 'mappedBy' a different entity and may not explicitly specify the '@JoinColumn'" );
} }
return explicitJoinColumn( joinColumn, comment, parent, inferredData, defaultColumnSuffix ); return explicitJoinColumn( joinColumn, /*comment,*/ parent, inferredData, defaultColumnSuffix );
} }
else { else {
return implicitJoinColumn( parent, inferredData, defaultColumnSuffix ); return implicitJoinColumn( parent, inferredData, defaultColumnSuffix );
@ -125,12 +124,12 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
private static AnnotatedJoinColumn explicitJoinColumn( private static AnnotatedJoinColumn explicitJoinColumn(
JoinColumn joinColumn, JoinColumn joinColumn,
Comment comment, // Comment comment,
AnnotatedJoinColumns parent, AnnotatedJoinColumns parent,
PropertyData inferredData, PropertyData inferredData,
String defaultColumnSuffix) { String defaultColumnSuffix) {
final AnnotatedJoinColumn column = new AnnotatedJoinColumn(); final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
column.setComment( comment != null ? comment.value() : null ); // column.setComment( comment != null ? comment.value() : null );
// column.setContext( context ); // column.setContext( context );
// column.setJoins( joins ); // column.setJoins( joins );
// column.setPropertyHolder( propertyHolder ); // column.setPropertyHolder( propertyHolder );

View File

@ -14,7 +14,6 @@ import java.util.Map;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure; import org.hibernate.AssertionFailure;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.JoinColumnOrFormula; import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinFormula; import org.hibernate.annotations.JoinFormula;
import org.hibernate.boot.model.naming.EntityNaming; import org.hibernate.boot.model.naming.EntityNaming;
@ -117,7 +116,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
public static AnnotatedJoinColumns buildJoinColumns( public static AnnotatedJoinColumns buildJoinColumns(
JoinColumn[] joinColumns, JoinColumn[] joinColumns,
Comment comment, // Comment comment,
String mappedBy, String mappedBy,
Map<String, Join> joins, Map<String, Join> joins,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
@ -125,7 +124,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
MetadataBuildingContext buildingContext) { MetadataBuildingContext buildingContext) {
return buildJoinColumnsWithDefaultColumnSuffix( return buildJoinColumnsWithDefaultColumnSuffix(
joinColumns, joinColumns,
comment, // comment,
mappedBy, mappedBy,
joins, joins,
propertyHolder, propertyHolder,
@ -137,7 +136,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix( public static AnnotatedJoinColumns buildJoinColumnsWithDefaultColumnSuffix(
JoinColumn[] joinColumns, JoinColumn[] joinColumns,
Comment comment, // Comment comment,
String mappedBy, String mappedBy,
Map<String, Join> joins, Map<String, Join> joins,
PropertyHolder propertyHolder, PropertyHolder propertyHolder,
@ -158,7 +157,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
if ( actualColumns == null || actualColumns.length == 0 ) { if ( actualColumns == null || actualColumns.length == 0 ) {
AnnotatedJoinColumn.buildJoinColumn( AnnotatedJoinColumn.buildJoinColumn(
null, null,
comment, // comment,
mappedBy, mappedBy,
parent, parent,
propertyHolder, propertyHolder,
@ -171,7 +170,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns {
for ( JoinColumn actualColumn : actualColumns ) { for ( JoinColumn actualColumn : actualColumns ) {
AnnotatedJoinColumn.buildJoinColumn( AnnotatedJoinColumn.buildJoinColumn(
actualColumn, actualColumn,
comment, // comment,
mappedBy, mappedBy,
parent, parent,
propertyHolder, propertyHolder,

View File

@ -749,7 +749,7 @@ public class BinderHelper {
final AnnotatedColumns discriminatorColumns = buildColumnOrFormulaFromAnnotation( final AnnotatedColumns discriminatorColumns = buildColumnOrFormulaFromAnnotation(
discriminatorColumn, discriminatorColumn,
discriminatorFormula, discriminatorFormula,
null, // null,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,

View File

@ -29,7 +29,6 @@ import org.hibernate.annotations.CollectionIdJdbcType;
import org.hibernate.annotations.CollectionIdJdbcTypeCode; import org.hibernate.annotations.CollectionIdJdbcTypeCode;
import org.hibernate.annotations.CollectionType; import org.hibernate.annotations.CollectionType;
import org.hibernate.annotations.Columns; import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.CompositeType; import org.hibernate.annotations.CompositeType;
import org.hibernate.annotations.Fetch; import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.Filter; import org.hibernate.annotations.Filter;
@ -282,7 +281,7 @@ public abstract class CollectionBinder {
collectionBinder.setInheritanceStatePerClass( inheritanceStatePerClass ); collectionBinder.setInheritanceStatePerClass( inheritanceStatePerClass );
collectionBinder.setDeclaringClass( inferredData.getDeclaringClass() ); collectionBinder.setDeclaringClass( inferredData.getDeclaringClass() );
final Comment comment = property.getAnnotation( Comment.class ); // final Comment comment = property.getAnnotation( Comment.class );
final Cascade hibernateCascade = property.getAnnotation( Cascade.class ); final Cascade hibernateCascade = property.getAnnotation( Cascade.class );
collectionBinder.setElementColumns( elementColumns( collectionBinder.setElementColumns( elementColumns(
@ -291,8 +290,8 @@ public abstract class CollectionBinder {
entityBinder, entityBinder,
context, context,
property, property,
virtualPropertyData( inferredData, property ), virtualPropertyData( inferredData, property )
comment // comment
) ); ) );
collectionBinder.setMapKeyColumns( mapKeyColumns( collectionBinder.setMapKeyColumns( mapKeyColumns(
@ -300,8 +299,8 @@ public abstract class CollectionBinder {
inferredData, inferredData,
entityBinder, entityBinder,
context, context,
property, property
comment // comment
) ); ) );
collectionBinder.setMapKeyManyToManyColumns( mapKeyJoinColumns( collectionBinder.setMapKeyManyToManyColumns( mapKeyJoinColumns(
@ -309,8 +308,8 @@ public abstract class CollectionBinder {
inferredData, inferredData,
entityBinder, entityBinder,
context, context,
property, property
comment // comment
) ); ) );
bindJoinedTableAssociation( bindJoinedTableAssociation(
@ -370,11 +369,11 @@ public abstract class CollectionBinder {
PropertyData inferredData, PropertyData inferredData,
EntityBinder entityBinder, EntityBinder entityBinder,
MetadataBuildingContext context, MetadataBuildingContext context,
XProperty property, XProperty property) {
Comment comment) { // Comment comment) {
return buildJoinColumnsWithDefaultColumnSuffix( return buildJoinColumnsWithDefaultColumnSuffix(
mapKeyJoinColumnAnnotations( propertyHolder, inferredData, property ), mapKeyJoinColumnAnnotations( propertyHolder, inferredData, property ),
comment, // comment,
null, null,
entityBinder.getSecondaryTables(), entityBinder.getSecondaryTables(),
propertyHolder, propertyHolder,
@ -528,12 +527,12 @@ public abstract class CollectionBinder {
EntityBinder entityBinder, EntityBinder entityBinder,
MetadataBuildingContext context, MetadataBuildingContext context,
XProperty property, XProperty property,
PropertyData virtualProperty, PropertyData virtualProperty) {
Comment comment) { // Comment comment) {
if ( property.isAnnotationPresent( jakarta.persistence.Column.class ) ) { if ( property.isAnnotationPresent( jakarta.persistence.Column.class ) ) {
return buildColumnFromAnnotation( return buildColumnFromAnnotation(
property.getAnnotation( jakarta.persistence.Column.class ), property.getAnnotation( jakarta.persistence.Column.class ),
comment, // comment,
nullability, nullability,
propertyHolder, propertyHolder,
virtualProperty, virtualProperty,
@ -544,7 +543,7 @@ public abstract class CollectionBinder {
else if ( property.isAnnotationPresent( Formula.class ) ) { else if ( property.isAnnotationPresent( Formula.class ) ) {
return buildFormulaFromAnnotation( return buildFormulaFromAnnotation(
getOverridableAnnotation(property, Formula.class, context), getOverridableAnnotation(property, Formula.class, context),
comment, // comment,
nullability, nullability,
propertyHolder, propertyHolder,
virtualProperty, virtualProperty,
@ -555,7 +554,7 @@ public abstract class CollectionBinder {
else if ( property.isAnnotationPresent( Columns.class ) ) { else if ( property.isAnnotationPresent( Columns.class ) ) {
return buildColumnsFromAnnotations( return buildColumnsFromAnnotations(
property.getAnnotation( Columns.class ).columns(), property.getAnnotation( Columns.class ).columns(),
comment, // comment,
nullability, nullability,
propertyHolder, propertyHolder,
virtualProperty, virtualProperty,
@ -565,7 +564,7 @@ public abstract class CollectionBinder {
} }
else { else {
return buildColumnFromNoAnnotation( return buildColumnFromNoAnnotation(
comment, // comment,
nullability, nullability,
propertyHolder, propertyHolder,
virtualProperty, virtualProperty,
@ -606,15 +605,15 @@ public abstract class CollectionBinder {
PropertyData inferredData, PropertyData inferredData,
EntityBinder entityBinder, EntityBinder entityBinder,
MetadataBuildingContext context, MetadataBuildingContext context,
XProperty property, XProperty property) {
Comment comment) { // Comment comment) {
return buildColumnsFromAnnotations( return buildColumnsFromAnnotations(
property.isAnnotationPresent( MapKeyColumn.class ) property.isAnnotationPresent( MapKeyColumn.class )
? new jakarta.persistence.Column[] { ? new jakarta.persistence.Column[] {
new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) ) new MapKeyColumnDelegator( property.getAnnotation( MapKeyColumn.class ) )
} }
: null, : null,
comment, // comment,
Nullability.FORCED_NOT_NULL, Nullability.FORCED_NOT_NULL,
propertyHolder, propertyHolder,
inferredData, inferredData,

View File

@ -8,7 +8,6 @@ package org.hibernate.boot.model.internal;
import org.hibernate.AnnotationException; import org.hibernate.AnnotationException;
import org.hibernate.annotations.Columns; import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula; import org.hibernate.annotations.Formula;
import org.hibernate.annotations.JoinColumnOrFormula; import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas; import org.hibernate.annotations.JoinColumnsOrFormulas;
@ -83,11 +82,11 @@ class ColumnsBuilder {
joinColumns = buildExplicitJoinColumns( property, inferredData ); joinColumns = buildExplicitJoinColumns( property, inferredData );
Comment comment = property.getAnnotation(Comment.class); // Comment comment = property.getAnnotation(Comment.class);
if ( property.isAnnotationPresent( Column.class ) ) { if ( property.isAnnotationPresent( Column.class ) ) {
columns = buildColumnFromAnnotation( columns = buildColumnFromAnnotation(
property.getAnnotation( Column.class ), property.getAnnotation( Column.class ),
comment, // comment,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -98,7 +97,7 @@ class ColumnsBuilder {
else if ( property.isAnnotationPresent( Formula.class ) ) { else if ( property.isAnnotationPresent( Formula.class ) ) {
columns = buildFormulaFromAnnotation( columns = buildFormulaFromAnnotation(
getOverridableAnnotation( property, Formula.class, buildingContext ), getOverridableAnnotation( property, Formula.class, buildingContext ),
comment, // comment,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -109,7 +108,7 @@ class ColumnsBuilder {
else if ( property.isAnnotationPresent( Columns.class ) ) { else if ( property.isAnnotationPresent( Columns.class ) ) {
columns = buildColumnsFromAnnotations( columns = buildColumnsFromAnnotations(
property.getAnnotation( Columns.class ).columns(), property.getAnnotation( Columns.class ).columns(),
comment, // comment,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -130,7 +129,7 @@ class ColumnsBuilder {
OneToMany oneToMany = property.getAnnotation( OneToMany.class ); OneToMany oneToMany = property.getAnnotation( OneToMany.class );
joinColumns = AnnotatedJoinColumns.buildJoinColumns( joinColumns = AnnotatedJoinColumns.buildJoinColumns(
null, null,
comment, // comment,
oneToMany == null ? null : nullIfEmpty( oneToMany.mappedBy() ), oneToMany == null ? null : nullIfEmpty( oneToMany.mappedBy() ),
entityBinder.getSecondaryTables(), entityBinder.getSecondaryTables(),
propertyHolder, propertyHolder,
@ -146,7 +145,7 @@ class ColumnsBuilder {
if ( columns == null && !property.isAnnotationPresent( ManyToMany.class ) ) { if ( columns == null && !property.isAnnotationPresent( ManyToMany.class ) ) {
//useful for collection of embedded elements //useful for collection of embedded elements
columns = buildColumnFromNoAnnotation( columns = buildColumnFromNoAnnotation(
comment, // comment,
nullability, nullability,
propertyHolder, propertyHolder,
inferredData, inferredData,
@ -166,7 +165,7 @@ class ColumnsBuilder {
private AnnotatedJoinColumns buildDefaultJoinColumnsForToOne(XProperty property, PropertyData inferredData) { private AnnotatedJoinColumns buildDefaultJoinColumnsForToOne(XProperty property, PropertyData inferredData) {
final JoinTable joinTableAnn = propertyHolder.getJoinTable( property ); final JoinTable joinTableAnn = propertyHolder.getJoinTable( property );
final Comment comment = property.getAnnotation(Comment.class); // final Comment comment = property.getAnnotation(Comment.class);
if ( joinTableAnn != null ) { if ( joinTableAnn != null ) {
if ( isEmpty( joinTableAnn.name() ) ) { if ( isEmpty( joinTableAnn.name() ) ) {
//TODO: I don't see why this restriction makes sense (use the same defaulting rule as for many-valued) //TODO: I don't see why this restriction makes sense (use the same defaulting rule as for many-valued)
@ -177,7 +176,7 @@ class ColumnsBuilder {
} }
return AnnotatedJoinColumns.buildJoinColumns( return AnnotatedJoinColumns.buildJoinColumns(
joinTableAnn.inverseJoinColumns(), joinTableAnn.inverseJoinColumns(),
comment, // comment,
null, null,
entityBinder.getSecondaryTables(), entityBinder.getSecondaryTables(),
propertyHolder, propertyHolder,
@ -189,7 +188,7 @@ class ColumnsBuilder {
OneToOne oneToOneAnn = property.getAnnotation( OneToOne.class ); OneToOne oneToOneAnn = property.getAnnotation( OneToOne.class );
return AnnotatedJoinColumns.buildJoinColumns( return AnnotatedJoinColumns.buildJoinColumns(
null, null,
comment, // comment,
oneToOneAnn == null ? null : nullIfEmpty( oneToOneAnn.mappedBy() ), oneToOneAnn == null ? null : nullIfEmpty( oneToOneAnn.mappedBy() ),
entityBinder.getSecondaryTables(), entityBinder.getSecondaryTables(),
propertyHolder, propertyHolder,
@ -205,7 +204,7 @@ class ColumnsBuilder {
if ( joinColumnAnnotations != null ) { if ( joinColumnAnnotations != null ) {
return AnnotatedJoinColumns.buildJoinColumns( return AnnotatedJoinColumns.buildJoinColumns(
joinColumnAnnotations, joinColumnAnnotations,
property.getAnnotation( Comment.class ), // property.getAnnotation( Comment.class ),
null, null,
entityBinder.getSecondaryTables(), entityBinder.getSecondaryTables(),
propertyHolder, propertyHolder,

View File

@ -45,7 +45,6 @@ import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache; import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy; import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Check; import org.hibernate.annotations.Check;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.DiscriminatorFormula; import org.hibernate.annotations.DiscriminatorFormula;
import org.hibernate.annotations.DiscriminatorOptions; import org.hibernate.annotations.DiscriminatorOptions;
import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicInsert;
@ -1678,10 +1677,10 @@ public class EntityBinder {
if ( rowId != null ) { if ( rowId != null ) {
table.setRowId( rowId.value() ); table.setRowId( rowId.value() );
} }
final Comment comment = annotatedClass.getAnnotation( Comment.class ); // final Comment comment = annotatedClass.getAnnotation( Comment.class );
if ( comment != null ) { // if ( comment != null ) {
table.setComment( comment.value() ); // table.setComment( comment.value() );
} // }
context.getMetadataCollector().addEntityTableXref( context.getMetadataCollector().addEntityTableXref(
persistentClass.getEntityName(), persistentClass.getEntityName(),

View File

@ -69,7 +69,7 @@ public class IdBagBinder extends BagBinder {
final AnnotatedColumns idColumns = AnnotatedColumn.buildColumnsFromAnnotations( final AnnotatedColumns idColumns = AnnotatedColumn.buildColumnsFromAnnotations(
new Column[] { collectionIdAnn.column() }, new Column[] { collectionIdAnn.column() },
null, // null,
Nullability.FORCED_NOT_NULL, Nullability.FORCED_NOT_NULL,
propertyHolder, propertyHolder,
propertyData, propertyData,

View File

@ -61,7 +61,6 @@ import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.ToOne; import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value; import org.hibernate.mapping.Value;
import org.hibernate.metamodel.spi.EmbeddableInstantiator; import org.hibernate.metamodel.spi.EmbeddableInstantiator;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.CompositeUserType;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -120,7 +119,7 @@ public class PropertyBinder {
private EntityBinder entityBinder; private EntityBinder entityBinder;
private boolean toMany; private boolean toMany;
private String referencedEntityName; private String referencedEntityName;
private PropertyAccessStrategy propertyAccessStrategy; // private PropertyAccessStrategy propertyAccessStrategy;
public void setReferencedEntityName(String referencedEntityName) { public void setReferencedEntityName(String referencedEntityName) {
this.referencedEntityName = referencedEntityName; this.referencedEntityName = referencedEntityName;
@ -190,10 +189,10 @@ public class PropertyBinder {
this.buildingContext = buildingContext; this.buildingContext = buildingContext;
} }
public void setPropertyAccessStrategy(PropertyAccessStrategy propertyAccessStrategy) { // public void setPropertyAccessStrategy(PropertyAccessStrategy propertyAccessStrategy) {
this.propertyAccessStrategy = propertyAccessStrategy; // this.propertyAccessStrategy = propertyAccessStrategy;
} // }
//
public void setDeclaringClass(XClass declaringClass) { public void setDeclaringClass(XClass declaringClass) {
this.declaringClass = declaringClass; this.declaringClass = declaringClass;
this.declaringClassSet = true; this.declaringClassSet = true;
@ -389,7 +388,7 @@ public class PropertyBinder {
property.setCascade( cascade ); property.setCascade( cascade );
property.setPropertyAccessorName( accessType.getType() ); property.setPropertyAccessorName( accessType.getType() );
property.setReturnedClassName( returnedClassName ); property.setReturnedClassName( returnedClassName );
property.setPropertyAccessStrategy( propertyAccessStrategy ); // property.setPropertyAccessStrategy( propertyAccessStrategy );
handleValueGeneration( property ); handleValueGeneration( property );
handleNaturalId( property ); handleNaturalId( property );
handleLob( property ); handleLob( property );

View File

@ -9,7 +9,6 @@ package org.hibernate.orm.test.annotations.comment;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import java.util.Iterator;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
@ -47,9 +46,7 @@ public class CommentTest {
.flatMap(namespace -> namespace.getTables().stream()).filter(t -> t.getName().equals(TABLE_NAME)) .flatMap(namespace -> namespace.getTables().stream()).filter(t -> t.getName().equals(TABLE_NAME))
.findFirst().orElse(null); .findFirst().orElse(null);
assertThat(table.getComment(), is(TABLE_COMMENT)); assertThat(table.getComment(), is(TABLE_COMMENT));
Iterator<Column> it = table.getColumns().iterator(); for (Column col : table.getColumns()) {
while (it.hasNext()) {
Column col = it.next();
assertThat(col.getComment(), is("I am " + col.getName())); assertThat(col.getComment(), is("I am " + col.getName()));
} }
} }