HHH-16388 Treat wrapper arrays with @Lob like the legacy mapping would

This commit is contained in:
Christian Beikov 2023-03-30 17:32:51 +02:00
parent 214b647f0f
commit 06bb9fb046
9 changed files with 33 additions and 11 deletions

View File

@ -20,6 +20,7 @@ import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Table;
import org.hibernate.tool.schema.extract.spi.ColumnTypeInformation;
import org.hibernate.type.AdjustableBasicType;
import org.hibernate.type.BasicPluralType;
import org.hibernate.type.BasicType;
import org.hibernate.type.SerializableType;
import org.hibernate.type.descriptor.converter.internal.NamedEnumValueConverter;
@ -199,9 +200,10 @@ public class InferredBasicValueResolver {
typeConfiguration,
dialect,
resolveSqlTypeIndicators( stdIndicators, registeredElementType, elementJtd ),
columnTypeInformation
columnTypeInformation,
stdIndicators
);
if ( registeredType != null ) {
if ( registeredType instanceof BasicPluralType<?, ?> ) {
typeConfiguration.getBasicTypeRegistry().register( registeredType );
}
}

View File

@ -437,8 +437,9 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
getTypeConfiguration(),
getDialect(),
registeredElementType,
column instanceof ColumnTypeInformation ? (ColumnTypeInformation) column : null
);
column instanceof ColumnTypeInformation ? (ColumnTypeInformation) column : null,
this
);
if ( registeredType != null ) {
getTypeConfiguration().getBasicTypeRegistry().register( registeredType );
@ -861,6 +862,7 @@ public class BasicValue extends SimpleValue implements JdbcTypeIndicators, Resol
@Internal
public boolean isDisallowedWrapperArray() {
return getBuildingContext().getBuildingOptions().getWrapperArrayHandling() == WrapperArrayHandling.DISALLOW
&& !isLob()
&& ( explicitJavaTypeAccess == null || explicitJavaTypeAccess.apply( getTypeConfiguration() ) == null )
&& isWrapperByteOrCharacterArray();
}

View File

@ -65,7 +65,8 @@ public abstract class AbstractArrayJavaType<T, E> extends AbstractClassJavaType<
TypeConfiguration typeConfiguration,
Dialect dialect,
BasicType<E> elementType,
ColumnTypeInformation columnTypeInformation) {
ColumnTypeInformation columnTypeInformation,
JdbcTypeIndicators stdIndicators) {
final Class<?> elementJavaTypeClass = elementType.getJavaTypeDescriptor().getJavaTypeClass();
if ( elementType instanceof BasicPluralType<?, ?> || elementJavaTypeClass != null && elementJavaTypeClass.isArray() ) {
return null;

View File

@ -28,6 +28,7 @@ import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
import org.hibernate.type.descriptor.jdbc.ArrayJdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
import org.hibernate.type.spi.TypeConfiguration;
/**
@ -55,7 +56,23 @@ public class ArrayJavaType<T> extends AbstractArrayJavaType<T[], T> {
TypeConfiguration typeConfiguration,
Dialect dialect,
BasicType<T> elementType,
ColumnTypeInformation columnTypeInformation) {
ColumnTypeInformation columnTypeInformation,
JdbcTypeIndicators stdIndicators) {
if ( stdIndicators.isLob() ) {
final Class<?> javaTypeClass = getJavaTypeClass();
if ( javaTypeClass == Byte[].class ) {
return typeConfiguration.getBasicTypeRegistry().resolve(
ByteArrayJavaType.INSTANCE,
ByteArrayJavaType.INSTANCE.getRecommendedJdbcType( stdIndicators )
);
}
if ( javaTypeClass == Character[].class ) {
return typeConfiguration.getBasicTypeRegistry().resolve(
CharacterArrayJavaType.INSTANCE,
CharacterArrayJavaType.INSTANCE.getRecommendedJdbcType( stdIndicators )
);
}
}
final Class<?> elementJavaTypeClass = elementType.getJavaTypeDescriptor().getJavaTypeClass();
if ( elementType instanceof BasicPluralType<?, ?> || elementJavaTypeClass != null && elementJavaTypeClass.isArray() ) {
return null;

View File

@ -12,6 +12,7 @@ import org.hibernate.Incubating;
import org.hibernate.dialect.Dialect;
import org.hibernate.tool.schema.extract.spi.ColumnTypeInformation;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;
import org.hibernate.type.spi.TypeConfiguration;
/**
@ -38,6 +39,7 @@ public interface BasicPluralJavaType<T> extends Serializable {
TypeConfiguration typeConfiguration,
Dialect dialect,
BasicType<T> elementType,
ColumnTypeInformation columnTypeInformation);
ColumnTypeInformation columnTypeInformation,
JdbcTypeIndicators stdIndicators);
}

View File

@ -94,7 +94,8 @@ public class BasicCollectionJavaType<C extends Collection<E>, E> extends Abstrac
TypeConfiguration typeConfiguration,
Dialect dialect,
BasicType<E> elementType,
ColumnTypeInformation columnTypeInformation) {
ColumnTypeInformation columnTypeInformation,
JdbcTypeIndicators stdIndicators) {
final Class<?> elementJavaTypeClass = elementType.getJavaTypeDescriptor().getJavaTypeClass();
if ( elementType instanceof BasicPluralType<?, ?>
|| elementJavaTypeClass != null && elementJavaTypeClass.isArray() ) {

View File

@ -145,7 +145,6 @@ public class ByteArrayMappingTests {
@Lob
private byte[] primitiveLob;
@Lob
@JavaType( ByteArrayJavaType.class )
private Byte[] wrapperLob;
//end::basic-bytearray-example[]

View File

@ -119,7 +119,6 @@ public class CharacterArrayMappingTests {
@Lob
char[] primitiveClob;
@Lob
@JavaType( CharacterArrayJavaType.class )
Character[] wrapperClob;
//end::basic-chararray-example[]
}

View File

@ -132,7 +132,6 @@ public class CharacterArrayNationalizedMappingTests {
char[] primitiveNClob;
@Lob
@Nationalized
@JavaType( CharacterArrayJavaType.class )
Character[] wrapperNClob;
//end::basic-nchararray-example[]
}