From c2728308b590042cd604c33bc789822e1a54958f Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Thu, 19 Sep 2024 10:44:49 +0200 Subject: [PATCH] HHH-18582 Throw explicit error when trying to map nested arrays --- .../java/org/hibernate/type/BasicTypeRegistry.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java b/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java index ae308bf8fd..c6f7c197bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java +++ b/hibernate-core/src/main/java/org/hibernate/type/BasicTypeRegistry.java @@ -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 BasicType resolvedType(ArrayJdbcType arrayType, BasicPluralJavaType castPluralJavaType) { + final BasicType 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; }