From d1c046e17c8d4d95650de89b473a0560f9920667 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Mon, 30 Dec 2024 17:10:14 +0100 Subject: [PATCH] various cleanups + improvements in org.hiberate.boot.model.internal 1. improve/cleanup logging (remove some log messages that don't naively seem more useful than lots of things we don't log) 2. report problems in AttributeConverter application using an error instead of a debug-level log message 3. various misc minor code cleanups in the Binders --- .../internal/AbstractPropertyHolder.java | 6 - .../boot/model/internal/AnnotatedColumn.java | 25 +- .../boot/model/internal/AnnotationBinder.java | 7 +- .../boot/model/internal/BasicValueBinder.java | 673 +++++++++--------- .../boot/model/internal/CollectionBinder.java | 24 +- .../internal/CollectionPropertyHolder.java | 42 +- .../model/internal/CollectionSecondPass.java | 7 +- .../boot/model/internal/EmbeddableBinder.java | 5 +- .../boot/model/internal/EntityBinder.java | 37 +- .../boot/model/internal/FilterDefBinder.java | 4 +- .../boot/model/internal/GeneratorBinder.java | 11 +- .../boot/model/internal/IdBagBinder.java | 6 +- .../boot/model/internal/PropertyBinder.java | 74 +- .../boot/model/internal/QueryBinder.java | 8 +- .../boot/model/internal/TableBinder.java | 6 - .../boot/model/internal/XMLContext.java | 27 +- .../hibernate/internal/CoreMessageLogger.java | 2 +- ...sIdPropertyBasicAttributeOverrideTest.java | 6 +- .../map/MapKeyAttributeConverterTest.java | 2 + .../orm/test/type/UUIDTypeConverterTest.java | 1 - 20 files changed, 455 insertions(+), 518 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java index 89700dbe94..6d25700958 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java @@ -21,7 +21,6 @@ import org.hibernate.boot.model.source.spi.AttributePath; import org.hibernate.boot.models.JpaAnnotations; import org.hibernate.boot.models.annotations.internal.ColumnJpaAnnotation; import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.internal.CoreLogging; import org.hibernate.internal.util.StringHelper; import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.ClassDetails; @@ -30,8 +29,6 @@ import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.usertype.internal.AbstractTimeZoneStorageCompositeUserType; import org.hibernate.usertype.internal.OffsetTimeCompositeUserType; -import org.jboss.logging.Logger; - import jakarta.persistence.AssociationOverride; import jakarta.persistence.AttributeOverride; import jakarta.persistence.Column; @@ -53,7 +50,6 @@ import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpt * @author Emmanuel Bernard */ public abstract class AbstractPropertyHolder implements PropertyHolder { - private static final Logger log = CoreLogging.logger( AbstractPropertyHolder.class ); private final String path; protected final AbstractPropertyHolder parent; @@ -106,8 +102,6 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { } } - log.debugf( "Attempting to locate auto-apply AttributeConverter for attributeMember [%s:%s]", path, attributeMember.getName() ); - return context.getMetadataCollector() .getConverterRegistry() .getAttributeConverterAutoApplyHandler() diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java index a04bef3fcf..813b6282c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java @@ -4,7 +4,6 @@ */ package org.hibernate.boot.model.internal; -import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -39,11 +38,10 @@ import org.hibernate.mapping.Table; import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.SourceModelBuildingContext; -import org.jboss.logging.Logger; - import static org.hibernate.boot.model.internal.BinderHelper.getPath; import static org.hibernate.boot.model.internal.BinderHelper.getRelativePath; import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; +import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.util.StringHelper.isBlank; import static org.hibernate.internal.util.StringHelper.isEmpty; import static org.hibernate.internal.util.StringHelper.isNotEmpty; @@ -69,7 +67,7 @@ import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpt */ public class AnnotatedColumn { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, AnnotatedColumn.class.getName() ); + private static final CoreMessageLogger LOG = messageLogger( AnnotatedColumn.class ); private Column mappingColumn; private boolean insertable = true; @@ -244,7 +242,9 @@ public class AnnotatedColumn { public void bind() { if ( isNotEmpty( formulaString ) ) { - LOG.debugf( "Binding formula %s", formulaString ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Binding formula: " + formulaString ); + } formula = new Formula(); formula.setFormula( formulaString ); } @@ -277,7 +277,7 @@ public class AnnotatedColumn { mappingColumn.setGeneratedAs( generatedAs ); } if ( LOG.isDebugEnabled() ) { - LOG.debugf( "Binding column: %s", toString() ); + LOG.debug( "Binding column: " + logicalColumnName ); } } } @@ -709,7 +709,9 @@ public class AnnotatedColumn { + " '@AttributeOverride's but the overridden property has " + overriddenCols.length + " columns (every column must have exactly one '@AttributeOverride')" ); } - LOG.debugf( "Column(s) overridden for property %s", inferredData.getPropertyName() ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Column mapping overridden for property: " + inferredData.getPropertyName() ); + } return isEmpty( overriddenCols ) ? null : overriddenCols; } else { @@ -1020,14 +1022,11 @@ public class AnnotatedColumn { public String toString() { final StringBuilder string = new StringBuilder(); string.append( getClass().getSimpleName() ).append( "(" ); - if ( isNotEmpty( logicalColumnName ) ) { - string.append( "column='" ).append( logicalColumnName ).append( "'," ); - } if ( isNotEmpty( formulaString ) ) { - string.append( "formula='" ).append( formulaString ).append( "'," ); + string.append( "formula='" ).append( formulaString ); } - if ( string.charAt( string.length()-1 ) == ',' ) { - string.setLength( string.length()-1 ); + else if ( isNotEmpty( logicalColumnName ) ) { + string.append( "column='" ).append( logicalColumnName ); } string.append( ")" ); return string.toString(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java index e30b1a7a03..2335f47e23 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java @@ -46,6 +46,7 @@ import jakarta.persistence.Table; import static org.hibernate.boot.model.internal.AnnotatedClassType.EMBEDDABLE; import static org.hibernate.boot.model.internal.AnnotatedClassType.ENTITY; +import static org.hibernate.boot.model.internal.EntityBinder.bindEntityClass; import static org.hibernate.boot.model.internal.FilterDefBinder.bindFilterDefs; import static org.hibernate.boot.model.internal.GeneratorParameters.interpretSequenceGenerator; import static org.hibernate.boot.model.internal.GeneratorParameters.interpretTableGenerator; @@ -79,7 +80,7 @@ public final class AnnotationBinder { interpretSequenceGenerator( generatorRegistration.configuration(), definitionBuilder ); final IdentifierGeneratorDefinition idGenDef = definitionBuilder.build(); if ( LOG.isTraceEnabled() ) { - LOG.tracef( "Adding global sequence generator with name: %s", name ); + LOG.trace( "Adding global sequence generator with name: " + name ); } context.getMetadataCollector().addDefaultIdentifierGenerator( idGenDef ); } ); @@ -89,7 +90,7 @@ public final class AnnotationBinder { interpretTableGenerator( generatorRegistration.configuration(), definitionBuilder ); final IdentifierGeneratorDefinition idGenDef = definitionBuilder.build(); if ( LOG.isTraceEnabled() ) { - LOG.tracef( "Adding global table generator with name: %s", name ); + LOG.trace( "Adding global table generator with name: " + name ); } context.getMetadataCollector().addDefaultIdentifierGenerator( idGenDef ); } ); @@ -217,7 +218,7 @@ public final class AnnotationBinder { // try to find class level generators // GeneratorBinder.registerGlobalGenerators( classDetails, context ); if ( context.getMetadataCollector().getClassType( classDetails ) == ENTITY ) { - EntityBinder.bindEntityClass( classDetails, inheritanceStatePerClass, context ); + bindEntityClass( classDetails, inheritanceStatePerClass, context ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java index a159d06617..68a2b25225 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java @@ -5,10 +5,9 @@ package org.hibernate.boot.model.internal; import java.io.Serializable; -import java.lang.invoke.MethodHandles; +import java.lang.annotation.Annotation; import java.lang.reflect.ParameterizedType; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -66,7 +65,6 @@ import org.hibernate.models.spi.ParameterizedTypeDetails; import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer; -import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.type.BasicType; import org.hibernate.type.SerializableToBlobType; @@ -83,8 +81,6 @@ import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.usertype.DynamicParameterizedType; import org.hibernate.usertype.UserType; -import org.jboss.logging.Logger; - import jakarta.persistence.DiscriminatorType; import jakarta.persistence.ElementCollection; import jakarta.persistence.EnumType; @@ -98,6 +94,9 @@ import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; import jakarta.persistence.Version; +import static java.util.Collections.emptyMap; +import static org.hibernate.boot.model.internal.AnnotationHelper.extractParameterMap; +import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; /** @@ -112,7 +111,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { // forward this class should undergo major changes: see the comments in #setType // but as always the "design" of these classes make it unclear exactly how to change it properly. - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, BasicValueBinder.class.getName() ); + private static final CoreMessageLogger LOG = messageLogger( BasicValueBinder.class ); public enum Kind { ATTRIBUTE( ValueMappingAccess.INSTANCE ), @@ -147,7 +146,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { private Function explicitMutabilityAccess; private Function implicitJavaTypeAccess; - private MemberDetails xproperty; + private MemberDetails memberDetails; private AccessType accessType; private ConverterDescriptor converterDescriptor; @@ -327,12 +326,12 @@ public class BasicValueBinder implements JdbcTypeIndicators { public void setType( - MemberDetails valueMember, + MemberDetails value, TypeDetails typeDetails, String declaringClassName, ConverterDescriptor converterDescriptor) { - this.xproperty = valueMember; - boolean isArray = valueMember.isArray(); + this.memberDetails = value; + final boolean isArray = value.isArray(); if ( typeDetails == null && !isArray ) { // we cannot guess anything return; @@ -346,25 +345,26 @@ public class BasicValueBinder implements JdbcTypeIndicators { // throw new AssertionFailure( "Expecting just one column, but found `" + Arrays.toString( columns ) + "`" ); // } - final TypeDetails modelClassDetails = isArray - ? valueMember.getElementType() - : typeDetails; + final TypeDetails modelClassDetails = isArray ? value.getElementType() : typeDetails; if ( kind != Kind.LIST_INDEX && kind != Kind.MAP_KEY ) { - isLob = valueMember.hasDirectAnnotationUsage( Lob.class ); + isLob = value.hasDirectAnnotationUsage( Lob.class ); } if ( getDialect().getNationalizationSupport() == NationalizationSupport.EXPLICIT ) { isNationalized = buildingContext.getBuildingOptions().useNationalizedCharacterData() - || valueMember.locateAnnotationUsage( Nationalized.class, getSourceModelContext() ) != null; + || value.locateAnnotationUsage( Nationalized.class, getSourceModelContext() ) != null; } - applyJpaConverter( valueMember, converterDescriptor ); + if ( converterDescriptor != null ) { + applyJpaConverter( value, converterDescriptor ); + } - final Class> userTypeImpl = kind.mappingAccess.customType( valueMember, getSourceModelContext() ); + final Class> userTypeImpl = + kind.mappingAccess.customType( value, getSourceModelContext() ); if ( userTypeImpl != null ) { - applyExplicitType( userTypeImpl, kind.mappingAccess.customTypeParameters( valueMember, getSourceModelContext() ) ); - + applyExplicitType( userTypeImpl, + kind.mappingAccess.customTypeParameters( value, getSourceModelContext() ) ); // An explicit custom UserType has top precedence when we get to BasicValue resolution. return; } @@ -374,43 +374,35 @@ public class BasicValueBinder implements JdbcTypeIndicators { final Class> registeredUserTypeImpl = buildingContext.getMetadataCollector().findRegisteredUserType( basicClass ); if ( registeredUserTypeImpl != null ) { - applyExplicitType( registeredUserTypeImpl, Collections.emptyMap() ); + applyExplicitType( registeredUserTypeImpl, emptyMap() ); return; } } switch ( kind ) { - case ATTRIBUTE: { - prepareBasicAttribute( declaringClassName, valueMember, typeDetails ); + case ATTRIBUTE: + prepareBasicAttribute( declaringClassName, value, typeDetails ); break; - } - case ANY_DISCRIMINATOR: { - prepareAnyDiscriminator( valueMember ); + case ANY_DISCRIMINATOR: + prepareAnyDiscriminator( value ); break; - } - case ANY_KEY: { - prepareAnyKey( valueMember ); + case ANY_KEY: + prepareAnyKey( value ); break; - } - case COLLECTION_ID: { - prepareCollectionId( valueMember ); + case COLLECTION_ID: + prepareCollectionId( value ); break; - } - case LIST_INDEX: { - prepareListIndex( valueMember ); + case LIST_INDEX: + prepareListIndex( value ); break; - } - case MAP_KEY: { - prepareMapKey( valueMember, typeDetails ); + case MAP_KEY: + prepareMapKey( value, typeDetails ); break; - } - case COLLECTION_ELEMENT: { - prepareCollectionElement( valueMember, typeDetails ); + case COLLECTION_ELEMENT: + prepareCollectionElement( value, typeDetails ); break; - } - default: { + default: throw new IllegalArgumentException( "Unexpected binder type : " + kind ); - } } } @@ -420,28 +412,31 @@ public class BasicValueBinder implements JdbcTypeIndicators { this.explicitLocalTypeParams = params; } - private void prepareCollectionId(MemberDetails attributeMember) { - final CollectionId collectionIdAnn = attributeMember.getDirectAnnotationUsage( CollectionId.class ); + private void prepareCollectionId(MemberDetails attribute) { + final CollectionId collectionIdAnn = attribute.getDirectAnnotationUsage( CollectionId.class ); if ( collectionIdAnn == null ) { throw new MappingException( "idbag mapping missing @CollectionId" ); } - final boolean useDeferredBeanContainerAccess = !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); + final boolean useDeferredBeanContainerAccess = + !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); final ManagedBeanRegistry beanRegistry = getManagedBeanRegistry(); explicitBasicTypeName = null; implicitJavaTypeAccess = (typeConfiguration) -> null; explicitJavaTypeAccess = (typeConfiguration) -> { - final CollectionIdJavaType javaTypeAnn = attributeMember.locateAnnotationUsage( CollectionIdJavaType.class, getSourceModelContext() ); + final CollectionIdJavaType javaTypeAnn = + attribute.locateAnnotationUsage( CollectionIdJavaType.class, getSourceModelContext() ); if ( javaTypeAnn != null ) { final Class> javaTypeClass = javaTypeAnn.value(); if ( javaTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ); } - final ManagedBean> bean = beanRegistry.getBean( javaTypeClass ); - return bean.getBeanInstance(); + else { + return beanRegistry.getBean( javaTypeClass ).getBeanInstance(); + } } } @@ -449,19 +444,22 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; explicitJdbcTypeAccess = (typeConfiguration) -> { - final CollectionIdJdbcType jdbcTypeAnn = attributeMember.locateAnnotationUsage( CollectionIdJdbcType.class, getSourceModelContext() ); + final CollectionIdJdbcType jdbcTypeAnn = + attribute.locateAnnotationUsage( CollectionIdJdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); } - final ManagedBean managedBean = beanRegistry.getBean( jdbcTypeClass ); - return managedBean.getBeanInstance(); + else { + return beanRegistry.getBean( jdbcTypeClass ).getBeanInstance(); + } } } - final CollectionIdJdbcTypeCode jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( CollectionIdJdbcTypeCode.class, getSourceModelContext() ); + final CollectionIdJdbcTypeCode jdbcTypeCodeAnn = + attribute.locateAnnotationUsage( CollectionIdJdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { final int code = jdbcTypeCodeAnn.value(); if ( code != Integer.MIN_VALUE ) { @@ -473,7 +471,8 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; explicitMutabilityAccess = (typeConfiguration) -> { - final CollectionIdMutability mutabilityAnn = attributeMember.locateAnnotationUsage( CollectionIdMutability.class, getSourceModelContext() ); + final CollectionIdMutability mutabilityAnn = + attribute.locateAnnotationUsage( CollectionIdMutability.class, getSourceModelContext() ); if ( mutabilityAnn != null ) { final Class> mutabilityClass = mutabilityAnn.value(); if ( mutabilityClass != null ) { @@ -483,7 +482,8 @@ public class BasicValueBinder implements JdbcTypeIndicators { // see if the value's type Class is annotated with mutability-related annotations if ( implicitJavaTypeAccess != null ) { - final Class attributeType = ReflectHelper.getClass( implicitJavaTypeAccess.apply( typeConfiguration ) ); + final Class attributeType = + ReflectHelper.getClass( implicitJavaTypeAccess.apply( typeConfiguration ) ); if ( attributeType != null ) { final Mutability attributeTypeMutabilityAnn = attributeType.getAnnotation( Mutability.class ); if ( attributeTypeMutabilityAnn != null ) { @@ -498,7 +498,8 @@ public class BasicValueBinder implements JdbcTypeIndicators { // if there is a converter, check it for mutability-related annotations if ( converterDescriptor != null ) { - final Mutability converterMutabilityAnn = converterDescriptor.getAttributeConverterClass().getAnnotation( Mutability.class ); + final Mutability converterMutabilityAnn = + converterDescriptor.getAttributeConverterClass().getAnnotation( Mutability.class ); if ( converterMutabilityAnn != null ) { return resolveMutability( converterMutabilityAnn.value() ); } @@ -509,7 +510,8 @@ public class BasicValueBinder implements JdbcTypeIndicators { } // if there is a UserType, see if its Class is annotated with mutability-related annotations - final Class> customTypeImpl = Kind.ATTRIBUTE.mappingAccess.customType( attributeMember, getSourceModelContext() ); + final Class> customTypeImpl = + Kind.ATTRIBUTE.mappingAccess.customType( attribute, getSourceModelContext() ); if ( customTypeImpl != null ) { final Mutability customTypeMutabilityAnn = customTypeImpl.getAnnotation( Mutability.class ); if ( customTypeMutabilityAnn != null ) { @@ -533,41 +535,49 @@ public class BasicValueBinder implements JdbcTypeIndicators { } private void prepareMapKey( - MemberDetails attributeMember, + MemberDetails attribute, TypeDetails explicitMapKeyTypeDetails) { - final TypeDetails mapKeyClass = explicitMapKeyTypeDetails == null - ? attributeMember.getMapKeyType() - : explicitMapKeyTypeDetails; + final TypeDetails mapKeyClass = + explicitMapKeyTypeDetails == null + ? attribute.getMapKeyType() + : explicitMapKeyTypeDetails; implicitJavaTypeAccess = typeConfiguration -> { final ClassDetails rawKeyClassDetails = mapKeyClass.determineRawClass(); return rawKeyClassDetails.toJavaClass(); }; - final MapKeyEnumerated mapKeyEnumeratedAnn = attributeMember.getDirectAnnotationUsage( MapKeyEnumerated.class ); + final MapKeyEnumerated mapKeyEnumeratedAnn = + attribute.getDirectAnnotationUsage( MapKeyEnumerated.class ); if ( mapKeyEnumeratedAnn != null ) { enumType = mapKeyEnumeratedAnn.value(); } - final MapKeyTemporal mapKeyTemporalAnn = attributeMember.getDirectAnnotationUsage( MapKeyTemporal.class ); + final MapKeyTemporal mapKeyTemporalAnn = + attribute.getDirectAnnotationUsage( MapKeyTemporal.class ); if ( mapKeyTemporalAnn != null ) { temporalPrecision = mapKeyTemporalAnn.value(); } - final boolean useDeferredBeanContainerAccess = !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); + final boolean useDeferredBeanContainerAccess = + !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); explicitJdbcTypeAccess = typeConfiguration -> { - final MapKeyJdbcType jdbcTypeAnn = attributeMember.locateAnnotationUsage( MapKeyJdbcType.class, getSourceModelContext() ); + final MapKeyJdbcType jdbcTypeAnn = + attribute.locateAnnotationUsage( MapKeyJdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); } - return getManagedBeanRegistry().getBean( jdbcTypeClass ).getBeanInstance(); + else { + return getManagedBeanRegistry().getBean( jdbcTypeClass ).getBeanInstance(); + } } } - final MapKeyJdbcTypeCode jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( MapKeyJdbcTypeCode.class, getSourceModelContext() ); + final MapKeyJdbcTypeCode jdbcTypeCodeAnn = + attribute.locateAnnotationUsage( MapKeyJdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { final int jdbcTypeCode = jdbcTypeCodeAnn.value(); if ( jdbcTypeCode != Integer.MIN_VALUE ) { @@ -579,27 +589,33 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; explicitJavaTypeAccess = typeConfiguration -> { - final MapKeyJavaType javaTypeAnn = attributeMember.locateAnnotationUsage( MapKeyJavaType.class, getSourceModelContext() ); + final MapKeyJavaType javaTypeAnn = + attribute.locateAnnotationUsage( MapKeyJavaType.class, getSourceModelContext() ); if ( javaTypeAnn != null ) { final Class> javaTypeClass = javaTypeAnn.value(); if ( javaTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ); } - return getManagedBeanRegistry().getBean( javaTypeClass ).getBeanInstance(); + else { + return getManagedBeanRegistry().getBean( javaTypeClass ).getBeanInstance(); + } } } - final MapKeyClass mapKeyClassAnn = attributeMember.getDirectAnnotationUsage( MapKeyClass.class ); + final MapKeyClass mapKeyClassAnn = attribute.getDirectAnnotationUsage( MapKeyClass.class ); if ( mapKeyClassAnn != null ) { - return (BasicJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor( mapKeyClassAnn.value() ); + return (BasicJavaType) + typeConfiguration.getJavaTypeRegistry() + .getDescriptor( mapKeyClassAnn.value() ); } return null; }; explicitMutabilityAccess = typeConfiguration -> { - final MapKeyMutability mutabilityAnn = attributeMember.locateAnnotationUsage( MapKeyMutability.class, getSourceModelContext() ); + final MapKeyMutability mutabilityAnn = + attribute.locateAnnotationUsage( MapKeyMutability.class, getSourceModelContext() ); if ( mutabilityAnn != null ) { final Class> mutabilityClass = mutabilityAnn.value(); if ( mutabilityClass != null ) { @@ -609,7 +625,8 @@ public class BasicValueBinder implements JdbcTypeIndicators { // see if the value's Java Class is annotated with mutability-related annotations if ( implicitJavaTypeAccess != null ) { - final Class attributeType = ReflectHelper.getClass( implicitJavaTypeAccess.apply( typeConfiguration ) ); + final Class attributeType = + ReflectHelper.getClass( implicitJavaTypeAccess.apply( typeConfiguration ) ); if ( attributeType != null ) { final Mutability attributeTypeMutabilityAnn = attributeType.getAnnotation( Mutability.class ); if ( attributeTypeMutabilityAnn != null ) { @@ -624,7 +641,8 @@ public class BasicValueBinder implements JdbcTypeIndicators { // if the value is converted, see if converter Class is annotated with mutability-related annotations if ( converterDescriptor != null ) { - final Mutability converterMutabilityAnn = converterDescriptor.getAttributeConverterClass().getAnnotation( Mutability.class ); + final Mutability converterMutabilityAnn = + converterDescriptor.getAttributeConverterClass().getAnnotation( Mutability.class ); if ( converterMutabilityAnn != null ) { return resolveMutability( converterMutabilityAnn.value() ); } @@ -635,7 +653,8 @@ public class BasicValueBinder implements JdbcTypeIndicators { } // if there is a UserType, see if its Class is annotated with mutability-related annotations - final Class> customTypeImpl = Kind.MAP_KEY.mappingAccess.customType( attributeMember, getSourceModelContext() ); + final Class> customTypeImpl = + Kind.MAP_KEY.mappingAccess.customType( attribute, getSourceModelContext() ); if ( customTypeImpl != null ) { final Mutability customTypeMutabilityAnn = customTypeImpl.getAnnotation( Mutability.class ); if ( customTypeMutabilityAnn != null ) { @@ -652,24 +671,27 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; } - private void prepareListIndex(MemberDetails attributeMember) { + private void prepareListIndex(MemberDetails attribute) { implicitJavaTypeAccess = typeConfiguration -> Integer.class; - final boolean useDeferredBeanContainerAccess = !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); + final boolean useDeferredBeanContainerAccess = + !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); final ManagedBeanRegistry beanRegistry = buildingContext.getBootstrapContext().getServiceRegistry() .requireService( ManagedBeanRegistry.class ); explicitJavaTypeAccess = (typeConfiguration) -> { - final ListIndexJavaType javaTypeAnn = attributeMember.locateAnnotationUsage( ListIndexJavaType.class, getSourceModelContext() ); + final ListIndexJavaType javaTypeAnn = + attribute.locateAnnotationUsage( ListIndexJavaType.class, getSourceModelContext() ); if ( javaTypeAnn != null ) { final Class> javaTypeClass = javaTypeAnn.value(); if ( javaTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ); } - final ManagedBean> bean = beanRegistry.getBean( javaTypeClass ); - return bean.getBeanInstance(); + else { + return beanRegistry.getBean( javaTypeClass ).getBeanInstance(); + } } } @@ -677,47 +699,52 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; explicitJdbcTypeAccess = (typeConfiguration) -> { - final ListIndexJdbcType jdbcTypeAnn = attributeMember.locateAnnotationUsage( ListIndexJdbcType.class, getSourceModelContext() ); + final ListIndexJdbcType jdbcTypeAnn = + attribute.locateAnnotationUsage( ListIndexJdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); } - final ManagedBean bean = beanRegistry.getBean( jdbcTypeClass ); - return bean.getBeanInstance(); + else { + return beanRegistry.getBean( jdbcTypeClass ).getBeanInstance(); + } } } - final ListIndexJdbcTypeCode jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( ListIndexJdbcTypeCode.class, getSourceModelContext() ); + final ListIndexJdbcTypeCode jdbcTypeCodeAnn = + attribute.locateAnnotationUsage( ListIndexJdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { return typeConfiguration.getJdbcTypeRegistry().getDescriptor( jdbcTypeCodeAnn.value() ); } - - return null; + else { + return null; + } }; } private void prepareCollectionElement( - MemberDetails attributeMember, + MemberDetails attribute, TypeDetails explicitElementTypeDetails) { - final TypeDetails elementTypeDetails = explicitElementTypeDetails == null && attributeMember.isArray() - ? attributeMember.getElementType() - : explicitElementTypeDetails; + final TypeDetails elementTypeDetails = + explicitElementTypeDetails == null && attribute.isArray() + ? attribute.getElementType() + : explicitElementTypeDetails; final ClassDetails rawElementType = elementTypeDetails.determineRawClass(); final java.lang.reflect.Type javaType = rawElementType.toJavaClass(); final Class javaTypeClass = ReflectHelper.getClass( javaType ); implicitJavaTypeAccess = typeConfiguration -> javaType; - final Temporal temporalAnn = attributeMember.getDirectAnnotationUsage( Temporal.class ); + final Temporal temporalAnn = attribute.getDirectAnnotationUsage( Temporal.class ); if ( temporalAnn != null ) { - DEPRECATION_LOGGER.deprecatedAnnotation( Temporal.class, attributeMember.getName() ); + DEPRECATION_LOGGER.deprecatedAnnotation( Temporal.class, attribute.getName() ); temporalPrecision = temporalAnn.value(); if ( temporalPrecision == null ) { throw new IllegalStateException( "No jakarta.persistence.TemporalType defined for @jakarta.persistence.Temporal " + - "associated with attribute " + attributeMember.getName() + "associated with attribute " + attribute.getName() ); } } @@ -726,13 +753,13 @@ public class BasicValueBinder implements JdbcTypeIndicators { } if ( javaTypeClass.isEnum() ) { - final Enumerated enumeratedAnn = attributeMember.getDirectAnnotationUsage( Enumerated.class ); + final Enumerated enumeratedAnn = attribute.getDirectAnnotationUsage( Enumerated.class ); if ( enumeratedAnn != null ) { enumType = enumeratedAnn.value(); if ( enumType == null ) { throw new IllegalStateException( "jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " + - " associated with attribute " + attributeMember.getName() + " associated with attribute " + attribute.getName() ); } } @@ -741,10 +768,11 @@ public class BasicValueBinder implements JdbcTypeIndicators { enumType = null; } - normalSupplementalDetails( attributeMember); + normalSupplementalDetails( attribute); // layer in support for JPA's approach for specifying a specific Java type for the collection elements... - final ElementCollection elementCollectionAnn = attributeMember.getDirectAnnotationUsage( ElementCollection.class ); + final ElementCollection elementCollectionAnn = + attribute.getDirectAnnotationUsage( ElementCollection.class ); if ( elementCollectionAnn != null ) { final Class targetClassDetails = elementCollectionAnn.targetClass(); if ( targetClassDetails != void.class) { @@ -755,10 +783,11 @@ public class BasicValueBinder implements JdbcTypeIndicators { if ( originalResult != null ) { return originalResult; } - - return (BasicJavaType) typeConfiguration - .getJavaTypeRegistry() - .getDescriptor( targetClassDetails ); + else { + return (BasicJavaType) + typeConfiguration.getJavaTypeRegistry() + .getDescriptor( targetClassDetails ); + } }; } } @@ -766,41 +795,44 @@ public class BasicValueBinder implements JdbcTypeIndicators { private void prepareBasicAttribute( String declaringClassName, - MemberDetails attributeMember, + MemberDetails attribute, TypeDetails attributeType) { final Class javaTypeClass = attributeType.determineRawClass().toJavaClass(); implicitJavaTypeAccess = ( typeConfiguration -> { if ( attributeType.getTypeKind() == TypeDetails.Kind.PARAMETERIZED_TYPE ) { return ParameterizedTypeImpl.from( attributeType.asParameterizedType() ); } - return attributeType.determineRawClass().toJavaClass(); + else { + return attributeType.determineRawClass().toJavaClass(); + } } ); //noinspection deprecation - final var temporalAnn = attributeMember.getDirectAnnotationUsage( Temporal.class ); + final var temporalAnn = attribute.getDirectAnnotationUsage( Temporal.class ); if ( temporalAnn != null ) { //noinspection deprecation - DEPRECATION_LOGGER.deprecatedAnnotation( Temporal.class, declaringClassName + "." + attributeMember.getName() ); - this.temporalPrecision = temporalAnn.value(); - if ( this.temporalPrecision == null ) { + DEPRECATION_LOGGER.deprecatedAnnotation( Temporal.class, + declaringClassName + "." + attribute.getName() ); + temporalPrecision = temporalAnn.value(); + if ( temporalPrecision == null ) { throw new IllegalStateException( "No jakarta.persistence.TemporalType defined for @jakarta.persistence.Temporal " + - "associated with attribute " + declaringClassName + "." + attributeMember.getName() + "associated with attribute " + declaringClassName + "." + attribute.getName() ); } } else { - this.temporalPrecision = null; + temporalPrecision = null; } - final Enumerated enumeratedAnn = attributeMember.getDirectAnnotationUsage( Enumerated.class ); + final Enumerated enumeratedAnn = attribute.getDirectAnnotationUsage( Enumerated.class ); if ( enumeratedAnn != null ) { - this.enumType = enumeratedAnn.value(); + enumType = enumeratedAnn.value(); if ( canUseEnumerated( attributeType, javaTypeClass ) ) { - if ( this.enumType == null ) { + if ( enumType == null ) { throw new IllegalStateException( "jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " + - " associated with attribute " + declaringClassName + "." + attributeMember.getName() + " associated with attribute " + declaringClassName + "." + attribute.getName() ); } } @@ -809,21 +841,22 @@ public class BasicValueBinder implements JdbcTypeIndicators { String.format( "Property '%s.%s' is annotated '@Enumerated' but its type '%s' is not an enum", declaringClassName, - attributeMember.getName(), + attribute.getName(), attributeType.getName() ) ); } } else { - this.enumType = null; + enumType = null; } - normalSupplementalDetails( attributeMember ); + normalSupplementalDetails( attribute ); } private boolean canUseEnumerated(TypeDetails javaType, Class javaTypeClass) { - if ( javaTypeClass.isEnum() || javaTypeClass.isArray() && javaTypeClass.getComponentType().isEnum() ) { + if ( javaTypeClass.isEnum() + || javaTypeClass.isArray() && javaTypeClass.getComponentType().isEnum() ) { return true; } if ( javaType.isImplementor( Collection.class ) ) { @@ -837,7 +870,8 @@ public class BasicValueBinder implements JdbcTypeIndicators { } private void prepareAnyDiscriminator(MemberDetails memberDetails) { - final AnyDiscriminator anyDiscriminatorAnn = memberDetails.locateAnnotationUsage( AnyDiscriminator.class, getSourceModelContext() ); + final AnyDiscriminator anyDiscriminatorAnn = + memberDetails.locateAnnotationUsage( AnyDiscriminator.class, getSourceModelContext() ); implicitJavaTypeAccess = (typeConfiguration) -> { if ( anyDiscriminatorAnn != null ) { @@ -862,71 +896,80 @@ public class BasicValueBinder implements JdbcTypeIndicators { if ( originalResolution != null ) { return originalResolution; } - - final Class hintedJavaType = (Class) implicitJavaTypeAccess.apply( typeConfiguration ); - final JavaType hintedDescriptor = typeConfiguration - .getJavaTypeRegistry() - .getDescriptor( hintedJavaType ); - return hintedDescriptor.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() ); + else { + final Class hintedJavaType = (Class) implicitJavaTypeAccess.apply( typeConfiguration ); + final JavaType hintedDescriptor = + typeConfiguration.getJavaTypeRegistry() + .getDescriptor( hintedJavaType ); + return hintedDescriptor.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() ); + } }; } - private void prepareAnyKey(MemberDetails memberDetails) { + private void prepareAnyKey(MemberDetails member) { implicitJavaTypeAccess = (typeConfiguration) -> null; - final boolean useDeferredBeanContainerAccess = !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); + final boolean useDeferredBeanContainerAccess = + !buildingContext.getBuildingOptions().isAllowExtensionsInCdi(); explicitJavaTypeAccess = (typeConfiguration) -> { - final AnyKeyJavaType javaTypeAnn = memberDetails.locateAnnotationUsage( AnyKeyJavaType.class, getSourceModelContext() ); + final AnyKeyJavaType javaTypeAnn = + member.locateAnnotationUsage( AnyKeyJavaType.class, getSourceModelContext() ); if ( javaTypeAnn != null ) { final Class> implClass = javaTypeAnn.value(); - if ( implClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( implClass ); } - return getManagedBeanRegistry().getBean( implClass ).getBeanInstance(); + else { + return getManagedBeanRegistry().getBean( implClass ).getBeanInstance(); + } } } - final AnyKeyJavaClass javaClassAnn = memberDetails.locateAnnotationUsage( AnyKeyJavaClass.class, getSourceModelContext() ); + final AnyKeyJavaClass javaClassAnn = + member.locateAnnotationUsage( AnyKeyJavaClass.class, getSourceModelContext() ); if ( javaClassAnn != null ) { - final Class impl = javaClassAnn.value(); - //noinspection rawtypes - return (BasicJavaType) typeConfiguration - .getJavaTypeRegistry() - .getDescriptor( impl ); + return (BasicJavaType) + typeConfiguration.getJavaTypeRegistry() + .getDescriptor( javaClassAnn.value() ); } // mainly used in XML interpretation - final AnyKeyType anyKeyTypeAnn = memberDetails.locateAnnotationUsage( AnyKeyType.class, getSourceModelContext() ); + final AnyKeyType anyKeyTypeAnn = + member.locateAnnotationUsage( AnyKeyType.class, getSourceModelContext() ); if ( anyKeyTypeAnn != null ) { final String namedType = anyKeyTypeAnn.value(); - final BasicType registeredType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( namedType ); + final BasicType registeredType = + typeConfiguration.getBasicTypeRegistry().getRegisteredType( namedType ); if ( registeredType == null ) { throw new MappingException( "Unrecognized @AnyKeyType value - " + namedType ); } - //noinspection rawtypes - return (BasicJavaType) registeredType.getJavaTypeDescriptor(); + else { + return (BasicJavaType) registeredType.getJavaTypeDescriptor(); + } } throw new MappingException("Could not determine key type for '@Any' mapping (specify '@AnyKeyJavaType' or '@AnyKeyJavaClass')"); }; explicitJdbcTypeAccess = (typeConfiguration) -> { - final AnyKeyJdbcType jdbcTypeAnn = memberDetails.locateAnnotationUsage( AnyKeyJdbcType.class, getSourceModelContext() ); + final AnyKeyJdbcType jdbcTypeAnn = + member.locateAnnotationUsage( AnyKeyJdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( useDeferredBeanContainerAccess ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); } - final ManagedBean jtdBean = getManagedBeanRegistry().getBean( jdbcTypeClass ); - return jtdBean.getBeanInstance(); + else { + return getManagedBeanRegistry().getBean( jdbcTypeClass ).getBeanInstance(); + } } } - final AnyKeyJdbcTypeCode jdbcTypeCodeAnn = memberDetails.locateAnnotationUsage( AnyKeyJdbcTypeCode.class, getSourceModelContext() ); + final AnyKeyJdbcTypeCode jdbcTypeCodeAnn = + member.locateAnnotationUsage( AnyKeyJdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { final int code = jdbcTypeCodeAnn.value(); if ( code != Integer.MIN_VALUE ) { @@ -938,20 +981,24 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; } - private void normalJdbcTypeDetails(MemberDetails attributeMember) { + private void normalJdbcTypeDetails(MemberDetails attribute) { explicitJdbcTypeAccess = typeConfiguration -> { - final org.hibernate.annotations.JdbcType jdbcTypeAnn = attributeMember.locateAnnotationUsage( org.hibernate.annotations.JdbcType.class, getSourceModelContext() ); + final org.hibernate.annotations.JdbcType jdbcTypeAnn = + attribute.locateAnnotationUsage( org.hibernate.annotations.JdbcType.class, getSourceModelContext() ); if ( jdbcTypeAnn != null ) { final Class jdbcTypeClass = jdbcTypeAnn.value(); if ( jdbcTypeClass != null ) { if ( !buildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass ); } - return getManagedBeanRegistry().getBean( jdbcTypeClass ).getBeanInstance(); + else { + return getManagedBeanRegistry().getBean( jdbcTypeClass ).getBeanInstance(); + } } } - final JdbcTypeCode jdbcTypeCodeAnn = attributeMember.locateAnnotationUsage( JdbcTypeCode.class, getSourceModelContext() ); + final JdbcTypeCode jdbcTypeCodeAnn = + attribute.locateAnnotationUsage( JdbcTypeCode.class, getSourceModelContext() ); if ( jdbcTypeCodeAnn != null ) { final int jdbcTypeCode = jdbcTypeCodeAnn.value(); if ( jdbcTypeCode != Integer.MIN_VALUE ) { @@ -969,10 +1016,11 @@ public class BasicValueBinder implements JdbcTypeIndicators { }; } - private void normalMutabilityDetails(MemberDetails attributeMember) { + private void normalMutabilityDetails(MemberDetails attribute) { explicitMutabilityAccess = typeConfiguration -> { // Look for `@Mutability` on the attribute - final Mutability mutabilityAnn = attributeMember.locateAnnotationUsage( Mutability.class, getSourceModelContext() ); + final Mutability mutabilityAnn = + attribute.locateAnnotationUsage( Mutability.class, getSourceModelContext() ); if ( mutabilityAnn != null ) { final Class> mutability = mutabilityAnn.value(); if ( mutability != null ) { @@ -981,7 +1029,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { } // Look for `@Immutable` on the attribute - if ( attributeMember.hasDirectAnnotationUsage( Immutable.class ) ) { + if ( attribute.hasDirectAnnotationUsage( Immutable.class ) ) { return ImmutableMutabilityPlan.instance(); } @@ -1003,7 +1051,6 @@ public class BasicValueBinder implements JdbcTypeIndicators { if ( attributeType != null ) { final Mutability classMutability = attributeType.getAnnotation( Mutability.class ); - if ( classMutability != null ) { final Class> mutability = classMutability.value(); if ( mutability != null ) { @@ -1020,25 +1067,26 @@ public class BasicValueBinder implements JdbcTypeIndicators { // if the value is converted, see if the converter Class is annotated `@Mutability` if ( converterDescriptor != null ) { - final Mutability converterMutabilityAnn = converterDescriptor.getAttributeConverterClass().getAnnotation( Mutability.class ); + final Mutability converterMutabilityAnn = + converterDescriptor.getAttributeConverterClass().getAnnotation( Mutability.class ); if ( converterMutabilityAnn != null ) { - final Class> mutability = converterMutabilityAnn.value(); - return resolveMutability( mutability ); + return resolveMutability( converterMutabilityAnn.value() ); } - final Immutable converterImmutableAnn = converterDescriptor.getAttributeConverterClass().getAnnotation( Immutable.class ); + final Immutable converterImmutableAnn = + converterDescriptor.getAttributeConverterClass().getAnnotation( Immutable.class ); if ( converterImmutableAnn != null ) { return ImmutableMutabilityPlan.instance(); } } // if a custom UserType is specified, see if the UserType Class is annotated `@Mutability` - final Class> customTypeImpl = Kind.ATTRIBUTE.mappingAccess.customType( attributeMember, getSourceModelContext() ); + final Class> customTypeImpl = + Kind.ATTRIBUTE.mappingAccess.customType( attribute, getSourceModelContext() ); if ( customTypeImpl != null ) { final Mutability customTypeMutabilityAnn = customTypeImpl.getAnnotation( Mutability.class ); if ( customTypeMutabilityAnn != null ) { - final Class> mutability = customTypeMutabilityAnn.value(); - return resolveMutability( mutability ); + return resolveMutability( customTypeMutabilityAnn.value() ); } final Immutable customTypeImmutableAnn = customTypeImpl.getAnnotation( Immutable.class ); @@ -1057,76 +1105,82 @@ public class BasicValueBinder implements JdbcTypeIndicators { if ( mutability.equals( Immutability.class ) ) { return Immutability.instance(); } - - if ( mutability.equals( ImmutableMutabilityPlan.class ) ) { + else if ( mutability.equals( ImmutableMutabilityPlan.class ) ) { return ImmutableMutabilityPlan.instance(); } - - if ( !buildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) { + else if ( !buildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( mutability ); } - - return getManagedBeanRegistry().getBean( mutability ).getBeanInstance(); + else { + return getManagedBeanRegistry().getBean( mutability ).getBeanInstance(); + } } - private void normalSupplementalDetails(MemberDetails attributeMember) { + private void normalSupplementalDetails(MemberDetails attribute) { explicitJavaTypeAccess = typeConfiguration -> { - final org.hibernate.annotations.JavaType javaType = attributeMember.locateAnnotationUsage( org.hibernate.annotations.JavaType.class, getSourceModelContext() ); + final org.hibernate.annotations.JavaType javaType = + attribute.locateAnnotationUsage( org.hibernate.annotations.JavaType.class, getSourceModelContext() ); if ( javaType != null ) { final Class> javaTypeClass = normalizeJavaType( javaType.value() ); if ( javaTypeClass != null ) { if ( !buildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) { return FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( javaTypeClass ); } - return getManagedBeanRegistry().getBean( javaTypeClass ).getBeanInstance(); + else { + return getManagedBeanRegistry().getBean( javaTypeClass ).getBeanInstance(); + } } } - //noinspection deprecation - final var targetAnn = attributeMember.locateAnnotationUsage( Target.class, getSourceModelContext() ); + final var targetAnn = attribute.locateAnnotationUsage( Target.class, getSourceModelContext() ); if ( targetAnn != null ) { - //noinspection deprecation - DEPRECATION_LOGGER.deprecatedAnnotation( Target.class, attributeMember.getName() ); - return (BasicJavaType) typeConfiguration.getJavaTypeRegistry().getDescriptor( targetAnn.value() ); + DEPRECATION_LOGGER.deprecatedAnnotation( Target.class, attribute.getName() ); + return (BasicJavaType) + typeConfiguration.getJavaTypeRegistry() + .getDescriptor( targetAnn.value() ); } return null; }; - final JdbcTypeCode jdbcType = attributeMember.locateAnnotationUsage( JdbcTypeCode.class, getSourceModelContext() ); + final JdbcTypeCode jdbcType = + attribute.locateAnnotationUsage( JdbcTypeCode.class, getSourceModelContext() ); if ( jdbcType != null ) { jdbcTypeCode = jdbcType.value(); } - normalJdbcTypeDetails( attributeMember); - normalMutabilityDetails( attributeMember ); + normalJdbcTypeDetails( attribute); + normalMutabilityDetails( attribute ); - final Enumerated enumerated = attributeMember.getDirectAnnotationUsage( Enumerated.class ); + final Enumerated enumerated = attribute.getDirectAnnotationUsage( Enumerated.class ); if ( enumerated != null ) { enumType = enumerated.value(); } - final Temporal temporal = attributeMember.getDirectAnnotationUsage( Temporal.class ); + final Temporal temporal = attribute.getDirectAnnotationUsage( Temporal.class ); if ( temporal != null ) { temporalPrecision = temporal.value(); } - final TimeZoneStorage timeZoneStorage = attributeMember.getDirectAnnotationUsage( TimeZoneStorage.class ); + final TimeZoneStorage timeZoneStorage = + attribute.getDirectAnnotationUsage( TimeZoneStorage.class ); if ( timeZoneStorage != null ) { timeZoneStorageType = timeZoneStorage.value(); - final TimeZoneColumn timeZoneColumnAnn = attributeMember.getDirectAnnotationUsage( TimeZoneColumn.class ); + final TimeZoneColumn timeZoneColumnAnn = + attribute.getDirectAnnotationUsage( TimeZoneColumn.class ); if ( timeZoneColumnAnn != null ) { - if ( timeZoneStorageType != TimeZoneStorageType.AUTO && timeZoneStorageType != TimeZoneStorageType.COLUMN ) { + if ( timeZoneStorageType != TimeZoneStorageType.AUTO + && timeZoneStorageType != TimeZoneStorageType.COLUMN ) { throw new IllegalStateException( - "@TimeZoneColumn can not be used in conjunction with @TimeZoneStorage( " + timeZoneStorageType + - " ) with attribute " + attributeMember.getDeclaringType().getName() + - '.' + attributeMember.getName() + "@TimeZoneColumn can not be used in conjunction with @TimeZoneStorage( " + + timeZoneStorageType + " ) with attribute " + + attribute.getDeclaringType().getName() + '.' + attribute.getName() ); } } } - this.partitionKey = attributeMember.hasDirectAnnotationUsage( PartitionKey.class ); + this.partitionKey = attribute.hasDirectAnnotationUsage( PartitionKey.class ); } private static Class> normalizeUserType(Class> userType) { @@ -1146,54 +1200,30 @@ public class BasicValueBinder implements JdbcTypeIndicators { return buildingContext.getMetadataCollector().getDatabase().getDialect(); } - private void applyJpaConverter(MemberDetails attributeMember, ConverterDescriptor attributeConverterDescriptor) { - if ( attributeConverterDescriptor == null ) { - return; - } - - LOG.debugf( "Applying JPA converter [%s:%s]", persistentClassName, attributeMember.getName() ); - - if ( attributeMember.hasDirectAnnotationUsage( Id.class ) ) { - LOG.debugf( "Skipping AttributeConverter checks for Id attribute [%s]", attributeMember.getName() ); - return; - } - - if ( attributeMember.hasDirectAnnotationUsage( Version.class ) ) { - LOG.debugf( "Skipping AttributeConverter checks for version attribute [%s]", attributeMember.getName() ); - return; - } - + private void applyJpaConverter(MemberDetails attribute, ConverterDescriptor attributeConverterDescriptor) { + disallowConverter( attribute, Id.class ); + disallowConverter( attribute, Version.class ); if ( kind == Kind.MAP_KEY ) { - if ( attributeMember.hasDirectAnnotationUsage( MapKeyTemporal.class ) ) { - LOG.debugf( "Skipping AttributeConverter checks for map-key annotated as MapKeyTemporal [%s]", attributeMember.getName() ); - return; - } - - if ( attributeMember.hasDirectAnnotationUsage( MapKeyEnumerated.class ) ) { - LOG.debugf( "Skipping AttributeConverter checks for map-key annotated as MapKeyEnumerated [%s]", attributeMember.getName() ); - return; - } + disallowConverter( attribute, MapKeyTemporal.class ); + disallowConverter( attribute, MapKeyEnumerated.class ); } else { - if ( attributeMember.hasDirectAnnotationUsage( Temporal.class ) ) { - LOG.debugf( "Skipping AttributeConverter checks for Temporal attribute [%s]", attributeMember.getName() ); - return; - } - - if ( attributeMember.hasDirectAnnotationUsage( Enumerated.class ) ) { - LOG.debugf( "Skipping AttributeConverter checks for Enumerated attribute [%s]", attributeMember.getName() ); - return; - } + disallowConverter( attribute, Temporal.class ); + disallowConverter( attribute, Enumerated.class ); } - if ( isAssociation() ) { - LOG.debugf( "Skipping AttributeConverter checks for association attribute [%s]", attributeMember.getName() ); - return; + throw new AnnotationException( "'AttributeConverter' not allowed for association '" + attribute.getName() + "'" ); } - this.converterDescriptor = attributeConverterDescriptor; } + void disallowConverter(MemberDetails attribute, Class annotationType) { + if ( attribute.hasDirectAnnotationUsage( annotationType ) ) { + throw new AnnotationException( "'AttributeConverter' not allowed for attribute '" + attribute.getName() + + "' annotated '@" + annotationType.getName() + "'" ); + } + } + private boolean isAssociation() { // todo : this information is only known to caller(s), need to pass that information in somehow. // or, is this enough? @@ -1211,7 +1241,9 @@ public class BasicValueBinder implements JdbcTypeIndicators { columns.checkPropertyConsistency(); - LOG.debugf( "building BasicValue for %s", propertyName ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Building BasicValue for property: " + propertyName ); + } if ( table == null ) { table = columns.getTable(); @@ -1294,11 +1326,10 @@ public class BasicValueBinder implements JdbcTypeIndicators { } public void fillSimpleValue() { - LOG.debugf( "Starting `BasicValueBinder#fillSimpleValue` for %s", propertyName ); - - final String explicitBasicTypeName = this.explicitBasicTypeName != null - ? this.explicitBasicTypeName - : this.timeStampVersionType; + final String explicitBasicTypeName = + this.explicitBasicTypeName != null + ? this.explicitBasicTypeName + : this.timeStampVersionType; basicValue.setExplicitTypeName( explicitBasicTypeName ); basicValue.setExplicitTypeParams( explicitLocalTypeParams ); @@ -1309,35 +1340,7 @@ public class BasicValueBinder implements JdbcTypeIndicators { // DynamicParameterizedType handling - just pass them (or a Supplier?) into // BasicValue so that it has access to them as needed - Class typeClass = null; - - if ( explicitBasicTypeName != null ) { - final TypeDefinition typeDefinition = buildingContext - .getTypeDefinitionRegistry() - .resolve( explicitBasicTypeName ); - if ( typeDefinition == null ) { - final BasicType registeredType = getTypeConfiguration() - .getBasicTypeRegistry() - .getRegisteredType( explicitBasicTypeName ); - if ( registeredType == null ) { - typeClass = buildingContext - .getBootstrapContext() - .getClassLoaderAccess() - .classForName( explicitBasicTypeName ); - } - } - else { - typeClass = typeDefinition.getTypeImplementorClass(); - } - } - // Enum type is parameterized and prior to Hibernate 6 we always resolved the type class - else if ( enumType != null || isEnum() ) { - typeClass = org.hibernate.type.EnumType.class; - } - // The Lob type is parameterized and prior to Hibernate 6 we always resolved the type class - else if ( isLob || isSerializable() ) { - typeClass = SerializableToBlobType.class; - } + Class typeClass = getTypeClass( explicitBasicTypeName ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -1391,16 +1394,50 @@ public class BasicValueBinder implements JdbcTypeIndicators { } } + private Class getTypeClass(String explicitBasicTypeName) { + if ( explicitBasicTypeName != null ) { + final TypeDefinition typeDefinition = + buildingContext.getTypeDefinitionRegistry() + .resolve( explicitBasicTypeName ); + if ( typeDefinition == null ) { + final BasicType registeredType = + getTypeConfiguration().getBasicTypeRegistry() + .getRegisteredType( explicitBasicTypeName ); + if ( registeredType == null ) { + return buildingContext.getBootstrapContext().getClassLoaderAccess() + .classForName( explicitBasicTypeName ); + } + else { + return null; + } + } + else { + return typeDefinition.getTypeImplementorClass(); + } + } + // Enum type is parameterized and prior to Hibernate 6 we always resolved the type class + else if ( enumType != null || isEnum() ) { + return org.hibernate.type.EnumType.class; + } + // The Lob type is parameterized and prior to Hibernate 6 we always resolved the type class + else if ( isLob || isSerializable() ) { + return SerializableToBlobType.class; + } + else { + return null; + } + } + private Map createDynamicParameterizedTypeParameters() { final Map parameters = new HashMap<>(); if ( returnedClassName == null ) { - throw new MappingException( "Returned class name not specified for basic mapping: " + xproperty.getName() ); + throw new MappingException( "Returned class name not specified for basic mapping: " + memberDetails.getName() ); } parameters.put( DynamicParameterizedType.RETURNED_CLASS, returnedClassName ); - parameters.put( DynamicParameterizedType.XPROPERTY, xproperty ); - parameters.put( DynamicParameterizedType.PROPERTY, xproperty.getName() ); + parameters.put( DynamicParameterizedType.XPROPERTY, memberDetails ); + parameters.put( DynamicParameterizedType.PROPERTY, memberDetails.getName() ); parameters.put( DynamicParameterizedType.IS_DYNAMIC, Boolean.toString( true ) ); parameters.put( DynamicParameterizedType.IS_PRIMARY_KEY, Boolean.toString( kind == Kind.MAP_KEY ) ); @@ -1425,65 +1462,49 @@ public class BasicValueBinder implements JdbcTypeIndicators { } private boolean isEnum() { - Class clazz = null; - if ( implicitJavaTypeAccess != null ) { - java.lang.reflect.Type type = implicitJavaTypeAccess.apply( getTypeConfiguration() ); - if ( type instanceof ParameterizedType ) { - type = ( (ParameterizedType) type ).getRawType(); - } - if ( type instanceof Class ) { - clazz = (Class) type; - } - } + final Class clazz = getValueClass(); return clazz != null && clazz.isEnum(); } private boolean isSerializable() { - Class clazz = null; - if ( implicitJavaTypeAccess != null ) { - java.lang.reflect.Type type = implicitJavaTypeAccess.apply( getTypeConfiguration() ); - if ( type instanceof ParameterizedType ) { - type = ( (ParameterizedType) type ).getRawType(); - } - if ( type instanceof Class ) { - clazz = (Class) type; - } - } + final Class clazz = getValueClass(); return clazz != null && Serializable.class.isAssignableFrom( clazz ); } - - + private Class getValueClass() { + if ( implicitJavaTypeAccess != null ) { + java.lang.reflect.Type type = implicitJavaTypeAccess.apply( getTypeConfiguration() ); + if ( type instanceof ParameterizedType parameterizedType ) { + type = parameterizedType.getRawType(); + } + if ( type instanceof Class cl ) { + return cl; + } + } + return null; + } /** * Access to detail of basic value mappings based on {@link Kind} */ private interface BasicMappingAccess { - Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext); - Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext); + Class> customType(MemberDetails attribute, SourceModelBuildingContext context); + Map customTypeParameters(MemberDetails attribute, SourceModelBuildingContext context); } private static class ValueMappingAccess implements BasicMappingAccess { public static final ValueMappingAccess INSTANCE = new ValueMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { - final Type customType = attributeMember.locateAnnotationUsage( Type.class, sourceModelContext ); - if ( customType == null ) { - return null; - } - - return normalizeUserType( customType.value() ); + public Class> customType(MemberDetails attribute, SourceModelBuildingContext context) { + final Type customType = attribute.locateAnnotationUsage( Type.class, context ); + return customType == null ? null : normalizeUserType( customType.value() ); } @Override - public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { - final Type customType = attributeMember.locateAnnotationUsage( Type.class, sourceModelContext ); - if ( customType == null ) { - return null; - } - - return AnnotationHelper.extractParameterMap( customType.parameters() ); + public Map customTypeParameters(MemberDetails attribute, SourceModelBuildingContext context) { + final Type customType = attribute.locateAnnotationUsage( Type.class, context ); + return customType == null ? null : extractParameterMap( customType.parameters() ); } } @@ -1491,13 +1512,13 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final AnyDiscriminatorMappingAccess INSTANCE = new AnyDiscriminatorMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { + public Class> customType(MemberDetails attribute, SourceModelBuildingContext context) { return null; } @Override - public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { - return Collections.emptyMap(); + public Map customTypeParameters(MemberDetails attribute, SourceModelBuildingContext context) { + return emptyMap(); } } @@ -1505,13 +1526,13 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final AnyKeyMappingAccess INSTANCE = new AnyKeyMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { + public Class> customType(MemberDetails attribute, SourceModelBuildingContext context) { return null; } @Override - public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { - return Collections.emptyMap(); + public Map customTypeParameters(MemberDetails attribute, SourceModelBuildingContext context) { + return emptyMap(); } } @@ -1519,23 +1540,17 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final MapKeyMappingAccess INSTANCE = new MapKeyMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { - final MapKeyType customType = attributeMember.locateAnnotationUsage( MapKeyType.class, sourceModelContext ); - if ( customType == null ) { - return null; - } + public Class> customType(MemberDetails attribute, SourceModelBuildingContext context) { + final MapKeyType customType = attribute.locateAnnotationUsage( MapKeyType.class, context ); + return customType == null ? null : normalizeUserType( customType.value() ); - return normalizeUserType( customType.value() ); } @Override - public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { - final MapKeyType customType = attributeMember.locateAnnotationUsage( MapKeyType.class, sourceModelContext ); - if ( customType == null ) { - return null; - } + public Map customTypeParameters(MemberDetails attribute, SourceModelBuildingContext context) { + final MapKeyType customType = attribute.locateAnnotationUsage( MapKeyType.class, context ); + return customType == null ? null : extractParameterMap( customType.parameters() ); - return AnnotationHelper.extractParameterMap( customType.parameters() ); } } @@ -1543,23 +1558,17 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final CollectionIdMappingAccess INSTANCE = new CollectionIdMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelBuildingContext) { - final CollectionIdType customType = attributeMember.locateAnnotationUsage( CollectionIdType.class, sourceModelBuildingContext ); - if ( customType == null ) { - return null; - } + public Class> customType(MemberDetails attribute, SourceModelBuildingContext context) { + final CollectionIdType customType = attribute.locateAnnotationUsage( CollectionIdType.class, context ); + return customType == null ? null : normalizeUserType( customType.value() ); - return normalizeUserType( customType.value() ); } @Override - public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { - final CollectionIdType customType = attributeMember.locateAnnotationUsage( CollectionIdType.class, sourceModelContext ); - if ( customType == null ) { - return null; - } + public Map customTypeParameters(MemberDetails attribute, SourceModelBuildingContext context) { + final CollectionIdType customType = attribute.locateAnnotationUsage( CollectionIdType.class, context ); + return customType == null ? null : extractParameterMap( customType.parameters() ); - return AnnotationHelper.extractParameterMap( customType.parameters() ); } } @@ -1567,13 +1576,13 @@ public class BasicValueBinder implements JdbcTypeIndicators { public static final ListIndexMappingAccess INSTANCE = new ListIndexMappingAccess(); @Override - public Class> customType(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { + public Class> customType(MemberDetails attribute, SourceModelBuildingContext context) { return null; } @Override - public Map customTypeParameters(MemberDetails attributeMember, SourceModelBuildingContext sourceModelContext) { - return Collections.emptyMap(); + public Map customTypeParameters(MemberDetails attribute, SourceModelBuildingContext context) { + return emptyMap(); } } } 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 ba1ce62ab9..f3d5b740b7 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 @@ -5,7 +5,6 @@ package org.hibernate.boot.model.internal; import java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandles; import java.util.Comparator; import java.util.HashMap; import java.util.List; @@ -117,7 +116,6 @@ import org.hibernate.usertype.CompositeUserType; import org.hibernate.usertype.ParameterizedType; import org.hibernate.usertype.UserCollectionType; -import org.jboss.logging.Logger; import jakarta.persistence.Access; import jakarta.persistence.AttributeOverride; @@ -168,6 +166,7 @@ import static org.hibernate.boot.model.internal.EmbeddableBinder.fillEmbeddable; import static org.hibernate.boot.model.internal.GeneratorBinder.visitIdGeneratorDefinitions; import static org.hibernate.boot.model.internal.PropertyHolderBuilder.buildPropertyHolder; import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.fromResultCheckStyle; +import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.util.ReflectHelper.getDefaultSupplier; import static org.hibernate.internal.util.StringHelper.getNonEmptyOrConjunctionIfBothNonEmpty; import static org.hibernate.internal.util.StringHelper.isBlank; @@ -185,7 +184,7 @@ import static org.hibernate.mapping.MappingHelper.createLocalUserCollectionTypeB * @author Emmanuel Bernard */ public abstract class CollectionBinder { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, CollectionBinder.class.getName() ); + private static final CoreMessageLogger LOG = messageLogger( CollectionBinder.class ); private static final List> INFERRED_CLASS_PRIORITY = List.of( List.class, @@ -1207,7 +1206,9 @@ public abstract class CollectionBinder { public void bind() { collection = createCollection( propertyHolder.getPersistentClass() ); final String role = qualify( propertyHolder.getPath(), propertyName ); - LOG.debugf( "Collection role: %s", role ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Binding collection role: " + role ); + } collection.setRole( role ); collection.setMappedByProperty( mappedBy ); @@ -1642,7 +1643,7 @@ public abstract class CollectionBinder { } /** - * return true if it's a Fk, false if it's an association table + * @return true if it's a foreign key, false if it's an association table */ protected boolean bindStarToManySecondPass(Map persistentClasses) { if ( noAssociationTable( persistentClasses ) ) { @@ -1740,9 +1741,6 @@ public abstract class CollectionBinder { else { collection.setCollectionTable( foreignJoinColumns.getTable() ); } - if ( LOG.isDebugEnabled() ) { - LOG.debugf( "Mapping collection: %s -> %s", getRole(), collection.getCollectionTable().getName() ); - } bindSynchronize(); bindFilters( false ); @@ -2952,7 +2950,7 @@ public abstract class CollectionBinder { private void logOneToManySecondPass() { if ( LOG.isDebugEnabled() ) { - LOG.debugf( "Binding a OneToMany: %s through a foreign key", safeCollectionRole() ); + LOG.debug( "Binding @OneToMany through foreign key: " + safeCollectionRole() ); } } @@ -2962,16 +2960,16 @@ public abstract class CollectionBinder { boolean isManyToAny) { if ( LOG.isDebugEnabled() ) { if ( isCollectionOfEntities && isOneToMany ) { - LOG.debugf( "Binding a OneToMany: %s through an association table", safeCollectionRole() ); + LOG.debug( "Binding @OneToMany through association table: " + safeCollectionRole() ); } else if ( isCollectionOfEntities ) { - LOG.debugf( "Binding a ManyToMany: %s", safeCollectionRole() ); + LOG.debug( "Binding @ManyToMany through association table: " + safeCollectionRole() ); } else if ( isManyToAny ) { - LOG.debugf( "Binding a ManyToAny: %s", safeCollectionRole() ); + LOG.debug( "Binding @ManyToAny: " + safeCollectionRole() ); } else { - LOG.debugf( "Binding a collection of element: %s", safeCollectionRole() ); + LOG.debug( "Binding @ElementCollection to collection table: " + safeCollectionRole() ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java index acee46bec0..88f6a46a43 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java @@ -14,7 +14,6 @@ import org.hibernate.annotations.ManyToAny; import org.hibernate.annotations.MapKeyType; import org.hibernate.boot.model.convert.spi.ConverterDescriptor; import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Join; @@ -36,6 +35,7 @@ import jakarta.persistence.MapKeyTemporal; import jakarta.persistence.OneToMany; import jakarta.persistence.Temporal; +import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.util.StringHelper.isEmpty; import static org.hibernate.internal.util.StringHelper.isNotEmpty; @@ -44,7 +44,7 @@ import static org.hibernate.internal.util.StringHelper.isNotEmpty; * @author Steve Ebersole */ public class CollectionPropertyHolder extends AbstractPropertyHolder { - private static final CoreMessageLogger log = CoreLogging.messageLogger( CollectionPropertyHolder.class ); + private static final CoreMessageLogger LOG = messageLogger( CollectionPropertyHolder.class ); private final Collection collection; @@ -111,11 +111,7 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, collectionProperty ); final String attributeName = info.getAttributeName(); if ( collection.isMap() ) { - final boolean specCompliant = isNotEmpty( attributeName ) - && ( attributeName.startsWith( "key" ) || attributeName.startsWith( "value" ) ); - if ( !specCompliant ) { - log.nonCompliantMapConversion( collection.getRole() ); - } + logSpecNoncompliance( attributeName, collection.getRole() ); } if ( isEmpty( attributeName ) ) { @@ -187,6 +183,14 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { } } + private static void logSpecNoncompliance(String attributeName, String role) { + final boolean specCompliant = isNotEmpty( attributeName ) + && (attributeName.startsWith( "key" ) || attributeName.startsWith( "value" ) ); + if ( !specCompliant ) { + LOG.nonCompliantMapConversion( role ); + } + } + /** * Check if path has the given prefix and remove it. * @@ -202,12 +206,12 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { if ( path.equals(prefix) ) { return ""; } - - if (path.startsWith(prefix + ".")) { + else if ( path.startsWith(prefix + ".") ) { return path.substring( prefix.length() + 1 ); } - - return defaultValue; + else { + return defaultValue; + } } @Override @@ -402,14 +406,6 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { } } } - - log.debugf( - "Attempting to locate auto-apply AttributeConverter for collection element [%s]", - collection.getRole() - ); - - // todo : do we need to pass along `XClass elementXClass`? - return getContext().getMetadataCollector() .getConverterRegistry() .getAttributeConverterAutoApplyHandler() @@ -433,14 +429,6 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { } } } - - log.debugf( - "Attempting to locate auto-apply AttributeConverter for collection key [%s]", - collection.getRole() - ); - - // todo : do we need to pass along `XClass keyXClass`? - return getContext().getMetadataCollector() .getConverterRegistry() .getAttributeConverterAutoApplyHandler() diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionSecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionSecondPass.java index 185c238455..f5c5221700 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionSecondPass.java @@ -4,7 +4,6 @@ */ package org.hibernate.boot.model.internal; -import java.lang.invoke.MethodHandles; import java.util.Map; import org.hibernate.MappingException; @@ -17,7 +16,7 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Value; -import org.jboss.logging.Logger; +import static org.hibernate.internal.CoreLogging.messageLogger; /** * Collection second pass @@ -26,7 +25,7 @@ import org.jboss.logging.Logger; */ public abstract class CollectionSecondPass implements SecondPass { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, CollectionSecondPass.class.getName() ); + private static final CoreMessageLogger LOG = messageLogger( CollectionSecondPass.class); private final Collection collection; @@ -38,7 +37,7 @@ public abstract class CollectionSecondPass implements SecondPass { public void doSecondPass(Map persistentClasses) throws MappingException { if ( LOG.isDebugEnabled() ) { - LOG.debugf( "Second pass for collection: %s", collection.getRole() ); + LOG.debug( "Second pass for collection: " + collection.getRole() ); } secondPass( persistentClasses ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java index 0b0f9384c1..0314e0b43b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java @@ -364,7 +364,9 @@ public class EmbeddableBinder { ); final String subpath = getPath( propertyHolder, inferredData ); - LOG.tracev( "Binding component with path: {0}", subpath ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Binding component with path: " + subpath ); + } final PropertyHolder subholder = buildPropertyHolder( component, subpath, @@ -602,7 +604,6 @@ public class EmbeddableBinder { PropertyHolder holder, MetadataBuildingContext context) { assert component.getDiscriminator() == null; - LOG.tracev( "Setting discriminator for embeddable {0}", component.getComponentClassName() ); final AnnotatedColumns columns = new AnnotatedColumns(); columns.setPropertyHolder( holder ); columns.setBuildingContext( context ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index 12d68efaab..6d57c1e698 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -5,7 +5,6 @@ package org.hibernate.boot.model.internal; import java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -106,8 +105,6 @@ import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.models.spi.TypeDetails; import org.hibernate.spi.NavigablePath; -import org.jboss.logging.Logger; - import jakarta.persistence.Access; import jakarta.persistence.AssociationOverride; import jakarta.persistence.AttributeOverride; @@ -136,6 +133,7 @@ import static org.hibernate.boot.model.internal.AnnotatedDiscriminatorColumn.bui import static org.hibernate.boot.model.internal.AnnotatedJoinColumn.buildInheritanceJoinColumn; import static org.hibernate.boot.model.internal.BinderHelper.extractFromPackage; import static org.hibernate.boot.model.internal.BinderHelper.getMappedSuperclassOrNull; +import static org.hibernate.boot.model.internal.BinderHelper.getPath; import static org.hibernate.boot.model.internal.BinderHelper.hasToOneAnnotation; import static org.hibernate.boot.model.internal.BinderHelper.noConstraint; import static org.hibernate.boot.model.internal.BinderHelper.toAliasEntityMap; @@ -152,6 +150,7 @@ import static org.hibernate.boot.model.internal.TableBinder.bindForeignKey; import static org.hibernate.boot.model.naming.Identifier.toIdentifier; import static org.hibernate.engine.OptimisticLockStyle.fromLockType; import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.fromResultCheckStyle; +import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.util.ReflectHelper.getDefaultSupplier; import static org.hibernate.internal.util.StringHelper.isBlank; import static org.hibernate.internal.util.StringHelper.isEmpty; @@ -170,7 +169,7 @@ import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpt */ public class EntityBinder { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, EntityBinder.class.getName() ); + private static final CoreMessageLogger LOG = messageLogger( EntityBinder.class ); private static final String NATURAL_ID_CACHE_SUFFIX = "##NaturalId"; private final MetadataBuildingContext context; @@ -217,7 +216,7 @@ public class EntityBinder { Map inheritanceStates, MetadataBuildingContext context) { if ( LOG.isDebugEnabled() ) { - LOG.debugf( "Binding entity from annotated class: %s", clazzToProcess.getName() ); + LOG.debug( "Binding entity from annotated class: " + clazzToProcess.getName() ); } final InFlightMetadataCollector collector = context.getMetadataCollector(); @@ -962,10 +961,8 @@ public class EntityBinder { discriminatorColumn.linkWithValue( discriminatorColumnBinding ); discriminatorColumnBinding.setTypeName( discriminatorColumn.getDiscriminatorTypeName() ); rootClass.setPolymorphic( true ); - final String rootEntityName = rootClass.getEntityName(); - LOG.tracev( "Setting discriminator for entity {0}", rootEntityName); getMetadataCollector() - .addSecondPass( new DiscriminatorColumnSecondPass( rootEntityName, + .addSecondPass( new DiscriminatorColumnSecondPass( rootClass.getEntityName(), context.getMetadataCollector().getDatabase().getDialect() ) ); } } @@ -1045,14 +1042,20 @@ public class EntityBinder { if ( discriminatorColumn != null ) { final boolean ignore = context.getBuildingOptions().ignoreExplicitDiscriminatorsForJoinedInheritance(); if ( ignore ) { - LOG.debugf( "Ignoring explicit @DiscriminatorColumn annotation on: %s", annotatedClass.getName() ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Ignoring explicit @DiscriminatorColumn annotation on: " + + annotatedClass.getName() ); + } } return !ignore; } else { final boolean createImplicit = context.getBuildingOptions().createImplicitDiscriminatorsForJoinedInheritance(); if ( createImplicit ) { - LOG.debugf( "Inferring implicit @DiscriminatorColumn using defaults for: %s", annotatedClass.getName() ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Inferring implicit @DiscriminatorColumn using defaults for: " + + annotatedClass.getName() ); + } } return createImplicit; } @@ -1073,8 +1076,7 @@ public class EntityBinder { if ( !idPropertiesIfIdClass.contains( propertyName ) ) { final MemberDetails property = propertyAnnotatedElement.getAttributeMember(); boolean hasIdAnnotation = hasIdAnnotation( property ); - if ( !idPropertiesIfIdClass.isEmpty() && !isIgnoreIdAnnotations() - && hasIdAnnotation ) { + if ( !idPropertiesIfIdClass.isEmpty() && !isIgnoreIdAnnotations() && hasIdAnnotation ) { missingEntityProperties.add( propertyName ); } else { @@ -1082,10 +1084,8 @@ public class EntityBinder { inheritanceState.getType() == SINGLE_TABLE && inheritanceState.hasParents(); if ( !hasIdAnnotation && property.hasAnnotationUsage( GeneratedValue.class, getSourceModelContext() ) ) { - throw new AnnotationException( - "Property '" - + BinderHelper.getPath( propertyHolder, propertyAnnotatedElement ) - + "' is annotated @GeneratedValue but is not part of an identifier" ); + throw new AnnotationException( "Property '" + getPath( propertyHolder, propertyAnnotatedElement ) + + "' is annotated '@GeneratedValue' but is not part of an identifier" ); } processElementAnnotations( propertyHolder, @@ -1194,7 +1194,6 @@ public class EntityBinder { context ); } - LOG.trace( "Subclass joined column(s) created" ); return joinColumns; } @@ -1389,7 +1388,6 @@ public class EntityBinder { } private void registerImportName() { - LOG.debugf( "Import with entity name %s", name ); try { final InFlightMetadataCollector metadataCollector = getMetadataCollector(); metadataCollector.addImport( name, persistentClass.getEntityName() ); @@ -1883,7 +1881,6 @@ public class EntityBinder { getMetadataCollector().addEntityTableXref( entityName, logicalName, table, denormalizedSuperTableXref ); if ( persistentClass instanceof TableOwner tableOwner ) { - LOG.debugf( "Bind entity %s on table %s", entityName, table.getName() ); tableOwner.setTable( table ); } else { @@ -2163,8 +2160,6 @@ public class EntityBinder { // Somehow keep joins() for later. // Has to do the work later because it needs PersistentClass id! - LOG.debugf( "Adding secondary table to entity %s -> %s", - entityName, join.getTable().getName() ); handleSecondaryRowManagement( join ); processSecondaryTableCustomSql( join ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java index cf46dc65ea..bf61da3821 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java @@ -96,7 +96,9 @@ public class FilterDefBinder { parameterResolvers ); - LOG.debugf( "Binding filter definition: %s", filterDefinition.getFilterName() ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Binding filter definition: " + filterDefinition.getFilterName() ); + } context.getMetadataCollector().addFilterDefinition( filterDefinition ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java index fa27b8a1ab..9157bb32c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java @@ -41,7 +41,6 @@ import org.hibernate.id.IdentityGenerator; import org.hibernate.id.PersistentIdentifierGenerator; import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.uuid.UuidValueGenerator; -import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.mapping.GeneratorCreator; import org.hibernate.mapping.KeyValue; @@ -70,6 +69,7 @@ import static org.hibernate.boot.model.internal.GeneratorParameters.interpretSeq import static org.hibernate.boot.model.internal.GeneratorParameters.interpretTableGenerator; import static org.hibernate.boot.model.internal.GeneratorStrategies.generatorClass; import static org.hibernate.id.IdentifierGenerator.GENERATOR_NAME; +import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.util.NullnessUtil.castNonNull; import static org.hibernate.internal.util.StringHelper.isNotEmpty; import static org.hibernate.internal.util.StringHelper.qualify; @@ -82,7 +82,7 @@ import static org.hibernate.internal.util.collections.CollectionHelper.combineUn */ public class GeneratorBinder { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( GeneratorBinder.class ); + private static final CoreMessageLogger LOG = messageLogger( GeneratorBinder.class ); public static final String ASSIGNED_GENERATOR_NAME = "assigned"; public static final GeneratorCreator ASSIGNED_IDENTIFIER_GENERATOR_CREATOR = @@ -243,8 +243,6 @@ public class GeneratorBinder { return globalDefinition; } else { - LOG.debugf( "Could not resolve explicit IdentifierGeneratorDefinition - using implicit interpretation (%s)", - name ); final GeneratedValue generatedValue = idAttributeMember.getDirectAnnotationUsage( GeneratedValue.class ); if ( generatedValue == null ) { throw new AssertionFailure( "No @GeneratedValue annotation" ); @@ -315,7 +313,6 @@ public class GeneratorBinder { LOG.tracev( "Added generator with name: {0}, strategy: {0}", definitionBuilder.getName(), definitionBuilder.getStrategy() ); } - return definitionBuilder.build(); } @@ -323,7 +320,7 @@ public class GeneratorBinder { final IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder(); interpretSequenceGenerator( generatorAnnotation, definitionBuilder ); if ( LOG.isTraceEnabled() ) { - LOG.tracev( "Add sequence generator with name: {0}", definitionBuilder.getName() ); + LOG.tracev( "Added sequence generator with name: {0}", definitionBuilder.getName() ); } return definitionBuilder.build(); } @@ -332,7 +329,7 @@ public class GeneratorBinder { final IdentifierGeneratorDefinition.Builder definitionBuilder = new IdentifierGeneratorDefinition.Builder(); interpretTableGenerator( generatorAnnotation, definitionBuilder ); if ( LOG.isTraceEnabled() ) { - LOG.tracev( "Add sequence generator with name: {0}", definitionBuilder.getName() ); + LOG.tracev( "Added sequence generator with name: {0}", definitionBuilder.getName() ); } return definitionBuilder.build(); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java index 8936f39617..9800eb66d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IdBagBinder.java @@ -104,13 +104,13 @@ public class IdBagBinder extends BagBinder { switch (namedGenerator) { case "identity": { - throw new MappingException("IDENTITY generation not supported for CollectionId"); + throw new MappingException("IDENTITY generation not supported for @CollectionId"); } case "assigned": { - throw new MappingException("Assigned generation not supported for CollectionId"); + throw new MappingException("Assigned generation not supported for @CollectionId"); } case "native": { - throw new MappingException("Native generation not supported for CollectionId"); + throw new MappingException("Native generation not supported for @CollectionId"); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java index ddc28d6ef9..66a6c15db4 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java @@ -5,7 +5,6 @@ package org.hibernate.boot.model.internal; import java.lang.annotation.Annotation; -import java.lang.invoke.MethodHandles; import java.util.Collection; import java.util.EnumSet; import java.util.List; @@ -43,7 +42,6 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.generator.BeforeExecutionGenerator; import org.hibernate.generator.EventType; import org.hibernate.generator.EventTypeSets; -import org.hibernate.internal.CoreMessageLogger; import org.hibernate.mapping.Component; import org.hibernate.mapping.Join; import org.hibernate.mapping.KeyValue; @@ -65,7 +63,6 @@ import org.hibernate.models.spi.TypeDetails; import org.hibernate.models.spi.TypeVariableScope; import org.hibernate.usertype.CompositeUserType; -import org.jboss.logging.Logger; import jakarta.persistence.Basic; import jakarta.persistence.Column; @@ -110,7 +107,6 @@ import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; * @author Emmanuel Bernard */ public class PropertyBinder { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, PropertyBinder.class.getName() ); private MetadataBuildingContext buildingContext; @@ -198,7 +194,7 @@ public class PropertyBinder { this.value = value; } - public void setComponentElement(Component componentElement) { + private void setComponentElement(Component componentElement) { this.componentElement = componentElement; } @@ -260,7 +256,6 @@ public class PropertyBinder { private Property makePropertyAndValue() { validateBind(); - LOG.debugf( "MetadataSourceProcessor property %s with lazy=%s", name, lazy ); final String containerClassName = holder.getClassName(); holder.startingProperty( memberDetails ); @@ -306,8 +301,8 @@ public class PropertyBinder { } catch ( Exception e ) { throw new AnnotationException( "error processing @AttributeBinderType annotation '" - + metaAnnotatedDescriptor.getAnnotationType().getName() + "' for property " - + qualify( holder.getPath(), name ), e ); + + metaAnnotatedDescriptor.getAnnotationType().getName() + "' for property '" + + qualify( holder.getPath(), name ) + "'", e ); } } } @@ -334,9 +329,7 @@ public class PropertyBinder { else { holder.addProperty( property, memberDetails, columns, declaringClass ); } - callAttributeBindersInSecondPass( property ); - return property; } @@ -365,10 +358,10 @@ public class PropertyBinder { rootClass.setEmbeddedIdentifier( true ); } else { - rootClass.setIdentifierProperty(property); + rootClass.setIdentifierProperty( property ); final MappedSuperclass superclass = getMappedSuperclassOrNull( declaringClass, inheritanceStatePerClass, buildingContext ); - setDeclaredIdentifier( rootClass, superclass, property); + setDeclaredIdentifier( rootClass, superclass, property ); } } } @@ -428,7 +421,6 @@ public class PropertyBinder { public Property makeProperty() { validateMake(); validateAnnotationsAgainstType(); - LOG.debugf( "Building property %s", name ); Property property = new Property(); property.setName( name ); property.setValue( value ); @@ -444,7 +436,6 @@ public class PropertyBinder { handleMutability( property ); handleOptional( property ); inferOptimisticLocking( property ); - LOG.tracev( "Cascading {0} with {1}", name, cascade ); return property; } @@ -535,11 +526,12 @@ public class PropertyBinder { private void validateAnnotationsAgainstType() { if ( memberDetails != null ) { - if ( !(memberDetails.getType() instanceof ArrayTypeDetails) ) { + final TypeDetails type = memberDetails.getType(); + if ( !(type instanceof ArrayTypeDetails) ) { checkAnnotation( OrderColumn.class, List.class ); if ( memberDetails.hasDirectAnnotationUsage( OrderBy.class ) - && !memberDetails.getType().isImplementor( Collection.class ) - && !memberDetails.getType().isImplementor( Map.class ) ) { + && !type.isImplementor( Collection.class ) + && !type.isImplementor( Map.class ) ) { throw new AnnotationException( "Property '" + qualify( holder.getPath(), name ) + "' is annotated '@OrderBy' but is not of type 'Collection' or 'Map'" ); } @@ -654,13 +646,9 @@ public class PropertyBinder { final Id existingIdProperty = attributeMember.getDirectAnnotationUsage( Id.class ); if ( incomingIdProperty != null && existingIdProperty == null ) { throw new MappingException( - String.format( - "You cannot override the [%s] non-identifier property from the [%s] base class or @MappedSuperclass and make it an identifier in the [%s] subclass", - attributeMember.getName(), - attributeMember.getDeclaringType().getName(), - property.getDeclaringType().getName() - ) - ); + "Attribute '" + attributeMember.getName() + + "' is declared by '" + attributeMember.getDeclaringType().getName() + + "' and may not be redeclared as an '@Id' by '" + property.getDeclaringType().getName() + "'" ); } } @@ -703,13 +691,10 @@ public class PropertyBinder { } private static boolean isJoinColumnPresent(String columnName, MemberDetails property, SourceModelBuildingContext modelContext) { - //The detection of a configured individual JoinColumn differs between Annotation - //and XML configuration processing. - final JoinColumn[] joinColumnAnnotations = property.getRepeatedAnnotationUsages( - JpaAnnotations.JOIN_COLUMN, - modelContext - ); - for ( JoinColumn joinColumnAnnotation : joinColumnAnnotations ) { + // The detection of a configured individual JoinColumn differs + // between Annotation and XML configuration processing. + for ( JoinColumn joinColumnAnnotation : + property.getRepeatedAnnotationUsages( JpaAnnotations.JOIN_COLUMN, modelContext ) ) { if ( joinColumnAnnotation.name().equals( columnName ) ) { return true; } @@ -736,26 +721,10 @@ public class PropertyBinder { MetadataBuildingContext context, Map inheritanceStatePerClass) throws MappingException { - if ( alreadyProcessedBySuper( propertyHolder, inferredData, entityBinder ) ) { - LOG.debugf( - "Skipping attribute [%s : %s] as it was already processed as part of super hierarchy", - inferredData.getClassOrElementName(), - inferredData.getPropertyName() - ); - } - else { + if ( !alreadyProcessedBySuper( propertyHolder, inferredData, entityBinder ) ) { // inSecondPass can only be used to apply right away the second pass of a composite-element // Because it's a value type, there is no bidirectional association, hence second pass // ordering does not matter - - if ( LOG.isTraceEnabled() ) { - LOG.tracev( - "Processing annotations of {0}.{1}" , - propertyHolder.getEntityName(), - inferredData.getPropertyName() - ); - } - final MemberDetails property = inferredData.getAttributeMember(); if ( property.hasDirectAnnotationUsage( Parent.class ) ) { handleParentProperty( propertyHolder, inferredData, property ); @@ -994,9 +963,6 @@ public class PropertyBinder { AnnotatedColumns columns, PropertyBinder propertyBinder) { checkVersionProperty( propertyHolder, isIdentifierMapper ); - if ( LOG.isTraceEnabled() ) { - LOG.tracev( "{0} is a version property", inferredData.getPropertyName() ); - } final RootClass rootClass = (RootClass) propertyHolder.getPersistentClass(); propertyBinder.setColumns( columns ); final Property property = propertyBinder.makePropertyValueAndBind(); @@ -1019,12 +985,6 @@ public class PropertyBinder { } rootClass.setOptimisticLockStyle( OptimisticLockStyle.VERSION ); - if ( LOG.isTraceEnabled() ) { - final SimpleValue versionValue = (SimpleValue) rootClass.getVersion().getValue(); - LOG.tracev( "Version name: {0}, unsavedValue: {1}", - rootClass.getVersion().getName(), - versionValue.getNullValue() ); - } } private static void checkVersionProperty(PropertyHolder propertyHolder, boolean isIdentifierMapper) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java index 102f0193b8..e674e9e774 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java @@ -4,7 +4,6 @@ */ package org.hibernate.boot.model.internal; -import java.lang.invoke.MethodHandles; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -42,8 +41,6 @@ import org.hibernate.query.sql.internal.ParameterParser; import org.hibernate.query.sql.spi.ParameterRecognizer; import org.hibernate.type.BasicType; -import org.jboss.logging.Logger; - import jakarta.persistence.CacheRetrieveMode; import jakarta.persistence.CacheStoreMode; import jakarta.persistence.NamedNativeQuery; @@ -55,6 +52,7 @@ import jakarta.persistence.SqlResultSetMapping; import jakarta.persistence.StoredProcedureParameter; import static java.lang.Boolean.TRUE; +import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; import static org.hibernate.internal.util.collections.ArrayHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.determineProperSizing; @@ -70,7 +68,7 @@ import static org.hibernate.models.internal.util.StringHelper.isEmpty; * @author Emmanuel Bernard */ public abstract class QueryBinder { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, QueryBinder.class.getName() ); + private static final CoreMessageLogger LOG = messageLogger( QueryBinder.class ); public static void bindQuery( NamedQuery namedQuery, @@ -464,7 +462,7 @@ public abstract class QueryBinder { else { context.getMetadataCollector().addNamedProcedureCallDefinition( definition ); } - LOG.debugf( "Bound named stored procedure query : %s => %s", + LOG.debugf( "Bound named stored procedure query: %s => %s", definition.getRegistrationName(), definition.getProcedureName() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java index b47cc0e0a1..f500427adf 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java @@ -4,7 +4,6 @@ */ package org.hibernate.boot.model.internal; -import java.lang.invoke.MethodHandles; import java.util.List; import org.hibernate.AnnotationException; @@ -20,7 +19,6 @@ import org.hibernate.boot.model.source.spi.AttributePath; import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.dialect.Dialect; -import org.hibernate.internal.CoreMessageLogger; import org.hibernate.mapping.Any; import org.hibernate.mapping.CheckConstraint; import org.hibernate.mapping.Collection; @@ -38,8 +36,6 @@ import org.hibernate.mapping.Table; import org.hibernate.mapping.ToOne; import org.hibernate.mapping.Value; -import org.jboss.logging.Logger; - import jakarta.persistence.Index; import jakarta.persistence.UniqueConstraint; @@ -56,7 +52,6 @@ import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpt * @author Emmanuel Bernard */ public class TableBinder { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, TableBinder.class.getName() ); private MetadataBuildingContext buildingContext; @@ -809,7 +804,6 @@ public class TableBinder { } private static List mappedByColumns(PersistentClass associatedClass, String mappedByProperty) { - LOG.debugf( "Retrieving property %s.%s", associatedClass.getEntityName(), mappedByProperty ); final Value value = associatedClass.getRecursiveProperty( mappedByProperty ).getValue(); if ( value instanceof Collection ) { final Value element = ((Collection) value).getElement(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/XMLContext.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/XMLContext.java index 558c80e391..65cef25908 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/XMLContext.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/XMLContext.java @@ -121,25 +121,27 @@ public class XMLContext implements Serializable { private void addClass(List managedTypes, String packageName, Default defaults, List addedClasses) { for ( JaxbManagedType element : managedTypes) { - String className = buildSafeClassName( element.getClazz(), packageName ); + final String className = buildSafeClassName( element.getClazz(), packageName ); if ( managedTypeOverride.containsKey( className ) ) { //maybe switch it to warn? throw new IllegalStateException( "Duplicate XML entry for " + className ); } addedClasses.add( className ); managedTypeOverride.put( className, element ); - Default mergedDefaults = new Default(); + final Default mergedDefaults = new Default(); // Apply entity mapping defaults mergedDefaults.overrideWithCatalogAndSchema( defaults ); // ... then apply entity settings - Default fileDefaults = new Default(); + final Default fileDefaults = new Default(); fileDefaults.setMetadataComplete( element.isMetadataComplete() ); fileDefaults.setAccess( element.getAccess() ); mergedDefaults.overrideWithCatalogAndSchema( fileDefaults ); // ... and we get the merged defaults for that entity defaultsOverride.put( className, mergedDefaults ); - LOG.debugf( "Adding XML overriding information for %s", className ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Adding XML overriding information for class: " + className ); + } if ( element instanceof JaxbEntityImpl ) { addEntityListenerClasses( ( (JaxbEntityImpl) element ).getEntityListenerContainer(), packageName, addedClasses ); } @@ -150,20 +152,23 @@ public class XMLContext implements Serializable { } private List addEntityListenerClasses(JaxbEntityListenerContainerImpl listeners, String packageName, List addedClasses) { - List localAddedClasses = new ArrayList<>(); + final List localAddedClasses = new ArrayList<>(); if ( listeners != null ) { - List elements = listeners.getEntityListeners(); + final List elements = listeners.getEntityListeners(); for ( JaxbEntityListenerImpl listener : elements ) { - String listenerClassName = buildSafeClassName( listener.getClazz(), packageName ); + final String listenerClassName = buildSafeClassName( listener.getClazz(), packageName ); if ( entityListenerOverride.containsKey( listenerClassName ) ) { LOG.duplicateListener( listenerClassName ); - continue; } - localAddedClasses.add( listenerClassName ); - entityListenerOverride.put( listenerClassName, listener ); + else { + localAddedClasses.add( listenerClassName ); + entityListenerOverride.put( listenerClassName, listener ); + } } } - LOG.debugf( "Adding XML overriding information for listeners: %s", localAddedClasses ); + if ( LOG.isDebugEnabled() ) { + LOG.debug( "Adding XML overriding information for entity listener classes: " + localAddedClasses ); + } addedClasses.addAll( localAddedClasses ); return localAddedClasses; } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 33c86c45c7..84af378f50 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -555,7 +555,7 @@ public interface CoreMessageLogger extends BasicLogger { @LogMessage(level = WARN) @Message( id = 449, - value = "@Convert annotation applied to Map attribute [%s] did not explicitly specify attributeName " + + value = "@Convert annotation applied to Map attribute [%s] did not explicitly specify 'attributeName' " + "using 'key'/'value' as required by spec; attempting to DoTheRightThing" ) void nonCompliantMapConversion(String collectionRole); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/mappedsuperclass/MappedSuperClassIdPropertyBasicAttributeOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/mappedsuperclass/MappedSuperClassIdPropertyBasicAttributeOverrideTest.java index a5fb0004fa..610cc6a96f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/mappedsuperclass/MappedSuperClassIdPropertyBasicAttributeOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/override/mappedsuperclass/MappedSuperClassIdPropertyBasicAttributeOverrideTest.java @@ -13,7 +13,6 @@ import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.util.ServiceRegistryUtil; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.fail; @@ -36,10 +35,7 @@ public class MappedSuperClassIdPropertyBasicAttributeOverrideTest { fail( "Should throw exception!" ); } catch (MappingException expected) { - assertEquals( - "You cannot override the [uid] non-identifier property from the [org.hibernate.orm.test.annotations.override.mappedsuperclass.MappedSuperClassWithUuidAsBasic] base class or @MappedSuperclass and make it an identifier in the [org.hibernate.orm.test.annotations.override.mappedsuperclass.SubclassWithUuidAsId] subclass", - expected.getMessage() - ); + // expected } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/map/MapKeyAttributeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/map/MapKeyAttributeConverterTest.java index 3cc8633b36..ca6d566d51 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/map/MapKeyAttributeConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/converted/converter/map/MapKeyAttributeConverterTest.java @@ -299,8 +299,10 @@ public class MapKeyAttributeConverterTest extends BaseNonConfigCoreFunctionalTes private ImplicitEnumMapKey enumImplicit; @Enumerated + @Convert(disableConversion = true) private ImplicitEnumMapKey enumImplicitOverrideOrdinal; @Enumerated(EnumType.STRING) + @Convert(disableConversion = true) private ImplicitEnumMapKey enumImplicitOverrideString; @Convert(converter = ImplicitEnumMapKeyOverridedConverter.class) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/UUIDTypeConverterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/UUIDTypeConverterTest.java index 3c95b01df3..e6d60b5f3f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/UUIDTypeConverterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/UUIDTypeConverterTest.java @@ -124,7 +124,6 @@ public class UUIDTypeConverterTest { public static class Id { @Column(unique = true, length = 16, nullable = false) @jakarta.persistence.Id - @Convert(converter = UuidBase64TypeConverter.class) private UUID id = safeRandomUUID(); }