HHH-17515 Fix constructor selection for integral types

This commit is contained in:
Marco Belladelli 2023-12-05 10:42:59 +01:00 committed by Christian Beikov
parent b8255af29b
commit 081b5977af
2 changed files with 22 additions and 16 deletions

View File

@ -75,14 +75,6 @@ public class Compatibility {
return areAssignmentCompatiblePrimitive( to, primitiveEquivalent( from ) );
}
}
else if ( isWrapper( to ) ) {
if ( from.isPrimitive() ) {
return areAssignmentCompatiblePrimitive( primitiveEquivalent( to ), from );
}
else if ( isWrapper( from ) ) {
return areAssignmentCompatiblePrimitive( primitiveEquivalent( to ), primitiveEquivalent( from ) );
}
}
return false;
}

View File

@ -148,20 +148,34 @@ public class DynamicInstantiationResultImpl<R> implements DynamicInstantiationRe
final Type[] genericParameterTypes = constructor.getGenericParameterTypes();
if ( genericParameterTypes.length == argumentReaders.size() ) {
for ( int i = 0; i < argumentReaders.size(); i++ ) {
final Type parameterType = genericParameterTypes[i];
final ArgumentReader<?> argumentReader = argumentReaders.get( i );
final JavaType<?> argumentTypeDescriptor = creationState.getSqlAstCreationContext()
.getMappingMetamodel()
.getTypeConfiguration()
.getJavaTypeRegistry()
.resolveDescriptor( genericParameterTypes[i] );
final boolean assignmentCompatible;
if ( parameterType instanceof Class<?> ) {
assignmentCompatible = areAssignmentCompatible(
(Class<?>) parameterType,
argumentReader.getAssembledJavaType().getJavaTypeClass()
);
}
else {
final JavaType<?> argumentTypeDescriptor = creationState.getSqlAstCreationContext()
.getMappingMetamodel()
.getTypeConfiguration()
.getJavaTypeRegistry()
.resolveDescriptor( parameterType );
assignmentCompatible = areAssignmentCompatible(
argumentTypeDescriptor,
argumentReader.getAssembledJavaType()
);
}
if ( !areAssignmentCompatible( argumentTypeDescriptor, argumentReader.getAssembledJavaType() ) ) {
if ( !assignmentCompatible ) {
if ( log.isDebugEnabled() ) {
log.debugf(
"Skipping constructor for dynamic-instantiation match due to argument mismatch [%s] : %s -> %s",
i,
constructor.getParameterTypes()[i].getName(),
argumentTypeDescriptor.getJavaType().getTypeName()
argumentReader.getAssembledJavaType().getTypeName(),
parameterType.getTypeName()
);
}
continue constructor_loop;