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;
import org.hibernate.binder.internal.CommentBinder;
import java.lang.annotation.Retention;
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.
* <p>
* By default, if {@link #on} is <em>not</em> specified:
* <ul>
* <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 field or property is annotated, the comment applies to the mapped column,
* <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>
* <p>
* But when {@link #on} is explicitly specified, the comment applies to the mapped table
* or column with the specified name.
*
* @author Yanming Zhou
*/
@TypeBinderType(binder = CommentBinder.class)
@AttributeBinderType(binder = CommentBinder.class)
@Target({METHOD, FIELD, TYPE})
@Retention(RUNTIME)
public @interface Comment {
/**
* The comment string.
* The text of the comment.
*/
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.Target;
import org.hibernate.Remove;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
@ -24,7 +22,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target({FIELD, METHOD, TYPE})
@Retention(RUNTIME)
@Deprecated( forRemoval = true )
@Remove( )
public @interface ForeignKey {
/**
* 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.
* <p>
* <em>Useful for secondary tables, otherwise use {@link Comment}.</em>
*
* @see Comment
* @deprecated use {@link Comment}
*/
@Deprecated(since = "6.2")
String comment() default "";
/**
@ -64,8 +63,8 @@ public @interface Table {
*
* @deprecated use {@link jakarta.persistence.SecondaryTable#foreignKey()}
*/
@Deprecated(since = "6.0")
ForeignKey foreignKey() default @ForeignKey( name="" );
@Deprecated(since = "6.0", forRemoval = true)
ForeignKey foreignKey() default @ForeignKey(name = "");
/**
* @deprecated This setting has no effect in Hibernate 6

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}
* 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;

View File

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

View File

@ -8,7 +8,6 @@ package org.hibernate.boot.model.internal;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.JoinFormula;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.ObjectNameNormalizer;
@ -84,7 +83,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
throw new AnnotationException( "Property '" + path
+ "' 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(
@ -104,7 +103,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
static AnnotatedJoinColumn buildJoinColumn(
JoinColumn joinColumn,
Comment comment,
// Comment comment,
String mappedBy,
AnnotatedJoinColumns parent,
PropertyHolder propertyHolder,
@ -116,7 +115,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
+ getRelativePath( propertyHolder, inferredData.getPropertyName() )
+ "' 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 {
return implicitJoinColumn( parent, inferredData, defaultColumnSuffix );
@ -125,12 +124,12 @@ public class AnnotatedJoinColumn extends AnnotatedColumn {
private static AnnotatedJoinColumn explicitJoinColumn(
JoinColumn joinColumn,
Comment comment,
// Comment comment,
AnnotatedJoinColumns parent,
PropertyData inferredData,
String defaultColumnSuffix) {
final AnnotatedJoinColumn column = new AnnotatedJoinColumn();
column.setComment( comment != null ? comment.value() : null );
// column.setComment( comment != null ? comment.value() : null );
// column.setContext( context );
// column.setJoins( joins );
// column.setPropertyHolder( propertyHolder );

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@ package org.hibernate.boot.model.internal;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
@ -83,11 +82,11 @@ class ColumnsBuilder {
joinColumns = buildExplicitJoinColumns( property, inferredData );
Comment comment = property.getAnnotation(Comment.class);
// Comment comment = property.getAnnotation(Comment.class);
if ( property.isAnnotationPresent( Column.class ) ) {
columns = buildColumnFromAnnotation(
property.getAnnotation( Column.class ),
comment,
// comment,
nullability,
propertyHolder,
inferredData,
@ -98,7 +97,7 @@ class ColumnsBuilder {
else if ( property.isAnnotationPresent( Formula.class ) ) {
columns = buildFormulaFromAnnotation(
getOverridableAnnotation( property, Formula.class, buildingContext ),
comment,
// comment,
nullability,
propertyHolder,
inferredData,
@ -109,7 +108,7 @@ class ColumnsBuilder {
else if ( property.isAnnotationPresent( Columns.class ) ) {
columns = buildColumnsFromAnnotations(
property.getAnnotation( Columns.class ).columns(),
comment,
// comment,
nullability,
propertyHolder,
inferredData,
@ -130,7 +129,7 @@ class ColumnsBuilder {
OneToMany oneToMany = property.getAnnotation( OneToMany.class );
joinColumns = AnnotatedJoinColumns.buildJoinColumns(
null,
comment,
// comment,
oneToMany == null ? null : nullIfEmpty( oneToMany.mappedBy() ),
entityBinder.getSecondaryTables(),
propertyHolder,
@ -146,7 +145,7 @@ class ColumnsBuilder {
if ( columns == null && !property.isAnnotationPresent( ManyToMany.class ) ) {
//useful for collection of embedded elements
columns = buildColumnFromNoAnnotation(
comment,
// comment,
nullability,
propertyHolder,
inferredData,
@ -166,7 +165,7 @@ class ColumnsBuilder {
private AnnotatedJoinColumns buildDefaultJoinColumnsForToOne(XProperty property, PropertyData inferredData) {
final JoinTable joinTableAnn = propertyHolder.getJoinTable( property );
final Comment comment = property.getAnnotation(Comment.class);
// final Comment comment = property.getAnnotation(Comment.class);
if ( joinTableAnn != null ) {
if ( isEmpty( joinTableAnn.name() ) ) {
//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(
joinTableAnn.inverseJoinColumns(),
comment,
// comment,
null,
entityBinder.getSecondaryTables(),
propertyHolder,
@ -189,7 +188,7 @@ class ColumnsBuilder {
OneToOne oneToOneAnn = property.getAnnotation( OneToOne.class );
return AnnotatedJoinColumns.buildJoinColumns(
null,
comment,
// comment,
oneToOneAnn == null ? null : nullIfEmpty( oneToOneAnn.mappedBy() ),
entityBinder.getSecondaryTables(),
propertyHolder,
@ -205,7 +204,7 @@ class ColumnsBuilder {
if ( joinColumnAnnotations != null ) {
return AnnotatedJoinColumns.buildJoinColumns(
joinColumnAnnotations,
property.getAnnotation( Comment.class ),
// property.getAnnotation( Comment.class ),
null,
entityBinder.getSecondaryTables(),
propertyHolder,

View File

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

View File

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

View File

@ -61,7 +61,6 @@ import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
import org.hibernate.metamodel.spi.EmbeddableInstantiator;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.usertype.CompositeUserType;
import org.jboss.logging.Logger;
@ -120,7 +119,7 @@ public class PropertyBinder {
private EntityBinder entityBinder;
private boolean toMany;
private String referencedEntityName;
private PropertyAccessStrategy propertyAccessStrategy;
// private PropertyAccessStrategy propertyAccessStrategy;
public void setReferencedEntityName(String referencedEntityName) {
this.referencedEntityName = referencedEntityName;
@ -190,10 +189,10 @@ public class PropertyBinder {
this.buildingContext = buildingContext;
}
public void setPropertyAccessStrategy(PropertyAccessStrategy propertyAccessStrategy) {
this.propertyAccessStrategy = propertyAccessStrategy;
}
// public void setPropertyAccessStrategy(PropertyAccessStrategy propertyAccessStrategy) {
// this.propertyAccessStrategy = propertyAccessStrategy;
// }
//
public void setDeclaringClass(XClass declaringClass) {
this.declaringClass = declaringClass;
this.declaringClassSet = true;
@ -389,7 +388,7 @@ public class PropertyBinder {
property.setCascade( cascade );
property.setPropertyAccessorName( accessType.getType() );
property.setReturnedClassName( returnedClassName );
property.setPropertyAccessStrategy( propertyAccessStrategy );
// property.setPropertyAccessStrategy( propertyAccessStrategy );
handleValueGeneration( property );
handleNaturalId( 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.core.Is.is;
import java.util.Iterator;
import java.util.stream.StreamSupport;
import jakarta.persistence.Entity;
@ -47,9 +46,7 @@ public class CommentTest {
.flatMap(namespace -> namespace.getTables().stream()).filter(t -> t.getName().equals(TABLE_NAME))
.findFirst().orElse(null);
assertThat(table.getComment(), is(TABLE_COMMENT));
Iterator<Column> it = table.getColumns().iterator();
while (it.hasNext()) {
Column col = it.next();
for (Column col : table.getColumns()) {
assertThat(col.getComment(), is("I am " + col.getName()));
}
}