HHH-18582 Throw explicit error when trying to map nested arrays

This commit is contained in:
Marco Belladelli 2024-09-19 10:44:49 +02:00
parent a21f4bf720
commit c2728308b5
1 changed files with 10 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import java.util.function.Supplier;
import org.hibernate.HibernateException;
import org.hibernate.Internal;
import org.hibernate.MappingException;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
@ -156,16 +157,24 @@ public class BasicTypeRegistry implements Serializable {
}
private <E> BasicType<?> resolvedType(ArrayJdbcType arrayType, BasicPluralJavaType<E> castPluralJavaType) {
final BasicType<E> elementType = resolve( castPluralJavaType.getElementJavaType(), arrayType.getElementJdbcType() );
final BasicType<?> resolvedType = castPluralJavaType.resolveType(
typeConfiguration,
typeConfiguration.getCurrentBaseSqlTypeIndicators().getDialect(),
resolve( castPluralJavaType.getElementJavaType(), arrayType.getElementJdbcType() ),
elementType,
null,
typeConfiguration.getCurrentBaseSqlTypeIndicators()
);
if ( resolvedType instanceof BasicPluralType<?,?> ) {
register( resolvedType );
}
else if ( resolvedType == null ) {
final Class<?> elementJavaTypeClass = elementType.getJavaTypeDescriptor().getJavaTypeClass();
if ( elementJavaTypeClass != null && elementJavaTypeClass.isArray() && elementJavaTypeClass != byte[].class ) {
// No support for nested arrays, except for byte[][]
throw new MappingException( "Nested arrays (with the exception of byte[][]) are not supported" );
}
}
return resolvedType;
}