replace log message with error

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-11-09 14:14:46 +01:00
parent cb38afc773
commit 5827a4fa41
3 changed files with 42 additions and 83 deletions

View File

@ -720,10 +720,6 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Creating pooled optimizer (lo) with [incrementSize=%s; returnClass=%s]", id = 467) @Message(value = "Creating pooled optimizer (lo) with [incrementSize=%s; returnClass=%s]", id = 467)
void creatingPooledLoOptimizer(int incrementSize, String name); void creatingPooledLoOptimizer(int incrementSize, String name);
@LogMessage(level = WARN)
@Message(value = "Unable to interpret type [%s] as an AttributeConverter due to an exception: %s", id = 468)
void logBadHbmAttributeConverterType(String type, String exceptionMessage);
@LogMessage(level = WARN) @LogMessage(level = WARN)
@Message(value = "An unexpected session is defined for a collection, but the collection is not connected to that session. A persistent collection may only be associated with one session at a time. Overwriting session. %s", id = 470) @Message(value = "An unexpected session is defined for a collection, but the collection is not connected to that session. A persistent collection may only be associated with one session at a time. Overwriting session. %s", id = 470)
void logUnexpectedSessionInCollectionNotConnected(String msg); void logUnexpectedSessionInCollectionNotConnected(String msg);

View File

@ -20,7 +20,6 @@ import org.hibernate.annotations.TimeZoneStorageType;
import org.hibernate.boot.internal.ClassmateContext; import org.hibernate.boot.internal.ClassmateContext;
import org.hibernate.boot.model.TypeDefinition; import org.hibernate.boot.model.TypeDefinition;
import org.hibernate.boot.model.convert.internal.AutoApplicableConverterDescriptorBypassedImpl; import org.hibernate.boot.model.convert.internal.AutoApplicableConverterDescriptorBypassedImpl;
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
import org.hibernate.boot.model.convert.internal.InstanceBasedConverterDescriptor; import org.hibernate.boot.model.convert.internal.InstanceBasedConverterDescriptor;
import org.hibernate.boot.model.convert.spi.AutoApplicableConverterDescriptor; import org.hibernate.boot.model.convert.spi.AutoApplicableConverterDescriptor;
import org.hibernate.boot.model.convert.spi.ConverterDescriptor; import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
@ -39,8 +38,6 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.jdbc.Size;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.SelectablePath; import org.hibernate.metamodel.mapping.SelectablePath;
import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer; import org.hibernate.resource.beans.internal.FallbackBeanInstanceProducer;
@ -80,7 +77,10 @@ import jakarta.persistence.EnumType;
import jakarta.persistence.TemporalType; import jakarta.persistence.TemporalType;
import static java.lang.Boolean.parseBoolean; import static java.lang.Boolean.parseBoolean;
import static org.hibernate.boot.model.convert.spi.ConverterDescriptor.TYPE_NAME_PREFIX;
import static org.hibernate.internal.util.ReflectHelper.reflectedPropertyType; import static org.hibernate.internal.util.ReflectHelper.reflectedPropertyType;
import static org.hibernate.internal.util.StringHelper.isEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty;
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
import static org.hibernate.mapping.MappingHelper.injectParameters; import static org.hibernate.mapping.MappingHelper.injectParameters;
@ -217,10 +217,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
} }
public Selectable getColumn() { public Selectable getColumn() {
if ( getColumnSpan() == 0 ) { return getColumnSpan() == 0 ? null : getColumn( 0 );
return null;
}
return getColumn( 0 );
} }
public java.lang.reflect.Type getResolvedJavaType() { public java.lang.reflect.Type getResolvedJavaType() {
@ -748,8 +745,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
return implicitJavaTypeAccess.apply(typeConfiguration); return implicitJavaTypeAccess.apply(typeConfiguration);
} }
else if ( ownerName != null && propertyName != null ) { else if ( ownerName != null && propertyName != null ) {
return reflectedPropertyType( ownerName, propertyName, return reflectedPropertyType( ownerName, propertyName, classLoaderService() );
getServiceRegistry().requireService( ClassLoaderService.class ) );
} }
else { else {
return null; return null;
@ -835,7 +831,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
// 3) basic type "resolution key" // 3) basic type "resolution key"
// 4) UserType or BasicType class name - directly, or through a TypeDefinition // 4) UserType or BasicType class name - directly, or through a TypeDefinition
if ( name.startsWith( ConverterDescriptor.TYPE_NAME_PREFIX ) ) { if ( name.startsWith( TYPE_NAME_PREFIX ) ) {
return NamedConverterResolution.from( return NamedConverterResolution.from(
name, name,
explicitJtdAccess, explicitJtdAccess,
@ -902,13 +898,12 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
// see if the name is a UserType or BasicType implementor class name // see if the name is a UserType or BasicType implementor class name
final ClassLoaderService cls = serviceRegistry.requireService( ClassLoaderService.class ); final ClassLoaderService classLoaderService = serviceRegistry.requireService( ClassLoaderService.class );
try { try {
final Class<?> typeNamedClass = cls.classForName( name ); final Class<?> typeNamedClass = classLoaderService.classForName( name );
// if there are no local config params, register an implicit TypeDefinition for this custom type . // if there are no local config params, register an implicit TypeDefinition for this custom type .
// later uses may find it and re-use its cacheable reference... // later uses may find it and re-use its cacheable reference...
if ( CollectionHelper.isEmpty( localTypeParams ) ) { if ( isEmpty( localTypeParams ) ) {
final TypeDefinition implicitDefinition = new TypeDefinition( final TypeDefinition implicitDefinition = new TypeDefinition(
name, name,
typeNamedClass, typeNamedClass,
@ -1012,30 +1007,17 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
} }
public void setTypeName(String typeName) { public void setTypeName(String typeName) {
if ( StringHelper.isNotEmpty( typeName ) ) { if ( isEmpty( typeName ) ) {
if ( typeName.startsWith( ConverterDescriptor.TYPE_NAME_PREFIX ) ) { super.setTypeName( typeName );
final String converterClassName = typeName.substring( ConverterDescriptor.TYPE_NAME_PREFIX.length() );
final ClassLoaderService cls = getServiceRegistry().requireService( ClassLoaderService.class );
try {
final Class<AttributeConverter<?,?>> converterClass = cls.classForName( converterClassName );
setAttributeConverterDescriptor( new ClassBasedConverterDescriptor(
converterClass,
false,
getBuildingContext().getBootstrapContext().getClassmateContext()
) );
return;
}
catch (Exception e) {
log.logBadHbmAttributeConverterType( typeName, e.getMessage() );
} }
else if ( typeName.startsWith( TYPE_NAME_PREFIX ) ) {
setAttributeConverterDescriptor( typeName );
} }
else { else {
setExplicitTypeName( typeName ); setExplicitTypeName( typeName );
}
}
super.setTypeName( typeName ); super.setTypeName( typeName );
} }
}
private static int COUNTER; private static int COUNTER;

View File

@ -37,7 +37,6 @@ import org.hibernate.generator.Generator;
import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.models.spi.MemberDetails; import org.hibernate.models.spi.MemberDetails;
import org.hibernate.models.spi.TypeDetails; import org.hibernate.models.spi.TypeDetails;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
@ -63,6 +62,7 @@ import static org.hibernate.boot.model.convert.spi.ConverterDescriptor.TYPE_NAME
import static org.hibernate.boot.model.internal.GeneratorBinder.ASSIGNED_GENERATOR_NAME; import static org.hibernate.boot.model.internal.GeneratorBinder.ASSIGNED_GENERATOR_NAME;
import static org.hibernate.boot.model.internal.GeneratorBinder.ASSIGNED_IDENTIFIER_GENERATOR_CREATOR; import static org.hibernate.boot.model.internal.GeneratorBinder.ASSIGNED_IDENTIFIER_GENERATOR_CREATOR;
import static org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl.fromExplicit; import static org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl.fromExplicit;
import static org.hibernate.internal.util.ReflectHelper.reflectedPropertyClass;
import static org.hibernate.internal.util.collections.ArrayHelper.toBooleanArray; import static org.hibernate.internal.util.collections.ArrayHelper.toBooleanArray;
/** /**
@ -208,7 +208,7 @@ public abstract class SimpleValue implements KeyValue {
} }
protected void justAddColumn(Column column, boolean insertable, boolean updatable) { protected void justAddColumn(Column column, boolean insertable, boolean updatable) {
int index = columns.indexOf( column ); final int index = columns.indexOf( column );
if ( index == -1 ) { if ( index == -1 ) {
columns.add( column ); columns.add( column );
insertability.add( insertable ); insertability.add( insertable );
@ -289,26 +289,23 @@ public abstract class SimpleValue implements KeyValue {
public void setTypeName(String typeName) { public void setTypeName(String typeName) {
if ( typeName != null && typeName.startsWith( TYPE_NAME_PREFIX ) ) { if ( typeName != null && typeName.startsWith( TYPE_NAME_PREFIX ) ) {
final String converterClassName = typeName.substring( TYPE_NAME_PREFIX.length() ); setAttributeConverterDescriptor( typeName );
final ClassLoaderService cls = getMetadata()
.getMetadataBuildingOptions()
.getServiceRegistry()
.requireService( ClassLoaderService.class );
try {
final Class<? extends AttributeConverter<?,?>> converterClass = cls.classForName( converterClassName );
this.attributeConverterDescriptor = new ClassBasedConverterDescriptor(
converterClass,
false,
( (InFlightMetadataCollector) getMetadata() ).getBootstrapContext().getClassmateContext()
);
return;
} }
catch (Exception e) { else {
log.logBadHbmAttributeConverterType( typeName, e.getMessage() ); this.typeName = typeName;
} }
} }
this.typeName = typeName; void setAttributeConverterDescriptor(String typeName) {
final String converterClassName = typeName.substring( TYPE_NAME_PREFIX.length() );
this.attributeConverterDescriptor =
new ClassBasedConverterDescriptor( classLoaderService().classForName( converterClassName ),
false, getBuildingContext().getBootstrapContext().getClassmateContext() );
}
ClassLoaderService classLoaderService() {
return getMetadata().getMetadataBuildingOptions().getServiceRegistry()
.requireService( ClassLoaderService.class );
} }
public void makeVersion() { public void makeVersion() {
@ -675,14 +672,7 @@ public abstract class SimpleValue implements KeyValue {
} }
private Class<?> getClass(String className, String propertyName) { private Class<?> getClass(String className, String propertyName) {
return ReflectHelper.reflectedPropertyClass( return reflectedPropertyClass( className, propertyName, classLoaderService() );
className,
propertyName,
getMetadata()
.getMetadataBuildingOptions()
.getServiceRegistry()
.requireService( ClassLoaderService.class )
);
} }
/** /**
@ -738,8 +728,8 @@ public abstract class SimpleValue implements KeyValue {
private <T> Type buildAttributeConverterTypeAdapter( private <T> Type buildAttributeConverterTypeAdapter(
JpaAttributeConverter<T, ?> jpaAttributeConverter) { JpaAttributeConverter<T, ?> jpaAttributeConverter) {
JavaType<T> domainJavaType = jpaAttributeConverter.getDomainJavaType(); final JavaType<T> domainJavaType = jpaAttributeConverter.getDomainJavaType();
JavaType<?> relationalJavaType = jpaAttributeConverter.getRelationalJavaType(); final JavaType<?> relationalJavaType = jpaAttributeConverter.getRelationalJavaType();
// build the SqlTypeDescriptor adapter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // build the SqlTypeDescriptor adapter ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Going back to the illustration, this should be a SqlTypeDescriptor that handles the Integer <-> String // Going back to the illustration, this should be a SqlTypeDescriptor that handles the Integer <-> String
@ -951,16 +941,11 @@ public abstract class SimpleValue implements KeyValue {
final MemberDetails attributeMember = (MemberDetails) typeParameters.get( DynamicParameterizedType.XPROPERTY ); final MemberDetails attributeMember = (MemberDetails) typeParameters.get( DynamicParameterizedType.XPROPERTY );
// todo : not sure this works for handling @MapKeyEnumerated // todo : not sure this works for handling @MapKeyEnumerated
final Annotation[] annotations = getAnnotations( attributeMember ); final Annotation[] annotations = getAnnotations( attributeMember );
final ClassLoaderService classLoaderService =
getMetadata().getMetadataBuildingOptions().getServiceRegistry()
.requireService( ClassLoaderService.class );
typeParameters.put( typeParameters.put(
DynamicParameterizedType.PARAMETER_TYPE, DynamicParameterizedType.PARAMETER_TYPE,
new ParameterTypeImpl( new ParameterTypeImpl(
classLoaderService.classForTypeName( classLoaderService()
typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) .classForTypeName( typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) ),
),
attributeMember != null ? attributeMember.getType() : null, attributeMember != null ? attributeMember.getType() : null,
annotations, annotations,
table.getCatalog(), table.getCatalog(),
@ -1003,13 +988,9 @@ public abstract class SimpleValue implements KeyValue {
final MemberDetails attributeMember = (MemberDetails) typeParameters.get( DynamicParameterizedType.XPROPERTY ); final MemberDetails attributeMember = (MemberDetails) typeParameters.get( DynamicParameterizedType.XPROPERTY );
// todo : not sure this works for handling @MapKeyEnumerated // todo : not sure this works for handling @MapKeyEnumerated
final Annotation[] annotations = getAnnotations( attributeMember ); final Annotation[] annotations = getAnnotations( attributeMember );
final ClassLoaderService classLoaderService =
getMetadata().getMetadataBuildingOptions().getServiceRegistry()
.requireService( ClassLoaderService.class );
return new ParameterTypeImpl( return new ParameterTypeImpl(
classLoaderService.classForTypeName( typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) ), classLoaderService()
.classForTypeName( typeParameters.getProperty(DynamicParameterizedType.RETURNED_CLASS) ),
attributeMember != null ? attributeMember.getType() : null, attributeMember != null ? attributeMember.getType() : null,
annotations, annotations,
table.getCatalog(), table.getCatalog(),