HHH-16479 Generic enum in @MappedSuperclass fails with java.lang.IllegalArgumentException: Named type [...] did not implement BasicType nor UserType

This commit is contained in:
Andrea Boriero 2023-04-17 12:43:30 +02:00 committed by Andrea Boriero
parent 962d483684
commit 5a49d04255
1 changed files with 66 additions and 48 deletions

View File

@ -29,6 +29,7 @@ import org.hibernate.resource.beans.spi.ManagedBean;
import org.hibernate.resource.beans.spi.ManagedBeanRegistry; import org.hibernate.resource.beans.spi.ManagedBeanRegistry;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.CustomType; import org.hibernate.type.CustomType;
import org.hibernate.type.JavaObjectType;
import org.hibernate.type.SerializableType; import org.hibernate.type.SerializableType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
@ -221,57 +222,14 @@ public class TypeDefinition implements Serializable {
// Series of backward compatible special cases // Series of backward compatible special cases
if ( Serializable.class.isAssignableFrom( typeImplementorClass ) ) { if ( Serializable.class.isAssignableFrom( typeImplementorClass ) ) {
final JavaType<Serializable> jtd = typeConfiguration
.getJavaTypeRegistry()
.resolveDescriptor( typeImplementorClass );
final JdbcType jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( Types.VARBINARY );
final BasicType<Serializable> resolved = InferredBasicValueResolver.resolveSqlTypeIndicators(
indicators,
typeConfiguration.getBasicTypeRegistry().resolve( jtd, jdbcType ),
jtd
);
@SuppressWarnings({"rawtypes", "unchecked"}) @SuppressWarnings({"rawtypes", "unchecked"})
final SerializableType legacyType = new SerializableType( typeImplementorClass ); final SerializableType legacyType = new SerializableType( typeImplementorClass );
return createBasicTypeResolution( legacyType, typeImplementorClass, indicators, typeConfiguration );
}
return new BasicValue.Resolution<>() { if ( indicators.getEnumeratedType() != null ) {
@Override assert typeImplementorClass.isInterface();
public JdbcMapping getJdbcMapping() { return createBasicTypeResolution( new JavaObjectType(), typeImplementorClass, indicators, typeConfiguration );
return resolved;
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
public BasicType getLegacyResolvedBasicType() {
return legacyType;
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
public JavaType getDomainJavaType() {
return resolved.getMappedJavaType();
}
@Override
public JavaType<?> getRelationalJavaType() {
return resolved.getMappedJavaType();
}
@Override
public JdbcType getJdbcType() {
return resolved.getJdbcType();
}
@Override
public BasicValueConverter getValueConverter() {
return resolved.getValueConverter();
}
@Override @SuppressWarnings({"rawtypes", "unchecked"})
public MutabilityPlan getMutabilityPlan() {
// a TypeDefinition does not explicitly provide a MutabilityPlan (yet?)
return resolved.isMutable()
? getDomainJavaType().getMutabilityPlan()
: ImmutableMutabilityPlan.instance();
}
};
} }
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -279,6 +237,66 @@ public class TypeDefinition implements Serializable {
); );
} }
private static BasicValue.Resolution<Object> createBasicTypeResolution(
BasicType<?> type,
Class<?> typeImplementorClass,
JdbcTypeIndicators indicators,
TypeConfiguration typeConfiguration
) {
final JavaType<Serializable> jtd = typeConfiguration
.getJavaTypeRegistry()
.resolveDescriptor( typeImplementorClass );
final JdbcType jdbcType = typeConfiguration.getJdbcTypeRegistry().getDescriptor( Types.VARBINARY );
final BasicType<Serializable> resolved = InferredBasicValueResolver.resolveSqlTypeIndicators(
indicators,
typeConfiguration.getBasicTypeRegistry().resolve( jtd, jdbcType ),
jtd
);
return new BasicValue.Resolution<>() {
@Override
public JdbcMapping getJdbcMapping() {
return resolved;
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public BasicType getLegacyResolvedBasicType() {
return type;
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public JavaType getDomainJavaType() {
return resolved.getMappedJavaType();
}
@Override
public JavaType<?> getRelationalJavaType() {
return resolved.getMappedJavaType();
}
@Override
public JdbcType getJdbcType() {
return resolved.getJdbcType();
}
@Override
public BasicValueConverter getValueConverter() {
return resolved.getValueConverter();
}
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public MutabilityPlan getMutabilityPlan() {
// a TypeDefinition does not explicitly provide a MutabilityPlan (yet?)
return resolved.isMutable()
? getDomainJavaType().getMutabilityPlan()
: ImmutableMutabilityPlan.instance();
}
};
}
private static Object instantiateType( private static Object instantiateType(
StandardServiceRegistry serviceRegistry, StandardServiceRegistry serviceRegistry,
MetadataBuildingOptions buildingOptions, MetadataBuildingOptions buildingOptions,