Skip to content

Commit

Permalink
HHH-16388 Treat wrapper arrays with @lob like the legacy mapping would
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Mar 30, 2023
1 parent b5220ff commit a35234a
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -199,9 +200,10 @@ else if ( JavaTypeHelper.isTemporal( elementJtd ) ) {
typeConfiguration,
dialect,
resolveSqlTypeIndicators( stdIndicators, registeredElementType, elementJtd ),
columnTypeInformation
columnTypeInformation,
stdIndicators
);
if ( registeredType != null ) {
if ( registeredType instanceof BasicPluralType<?, ?> ) {
typeConfiguration.getBasicTypeRegistry().register( registeredType );
}
}
Expand Down
Expand Up @@ -437,8 +437,9 @@ public TypeConfiguration getTypeConfiguration() {
getTypeConfiguration(),
getDialect(),
registeredElementType,
column instanceof ColumnTypeInformation ? (ColumnTypeInformation) column : null
);
column instanceof ColumnTypeInformation ? (ColumnTypeInformation) column : null,
this
);
if ( registeredType != null ) {
getTypeConfiguration().getBasicTypeRegistry().register( registeredType );

Expand Down Expand Up @@ -861,6 +862,7 @@ public Object accept(ValueVisitor visitor) {
@Internal
public boolean isDisallowedWrapperArray() {
return getBuildingContext().getBuildingOptions().getWrapperArrayHandling() == WrapperArrayHandling.DISALLOW
&& !isLob()
&& ( explicitJavaTypeAccess == null || explicitJavaTypeAccess.apply( getTypeConfiguration() ) == null )
&& isWrapperByteOrCharacterArray();
}
Expand Down
Expand Up @@ -65,7 +65,8 @@ public BasicType<?> resolveType(
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;
Expand Down
Expand Up @@ -28,6 +28,7 @@
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;

/**
Expand Down Expand Up @@ -55,7 +56,23 @@ public BasicType<?> resolveType(
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;
Expand Down
Expand Up @@ -12,6 +12,7 @@
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;

/**
Expand All @@ -38,6 +39,7 @@ BasicType<?> resolveType(
TypeConfiguration typeConfiguration,
Dialect dialect,
BasicType<T> elementType,
ColumnTypeInformation columnTypeInformation);
ColumnTypeInformation columnTypeInformation,
JdbcTypeIndicators stdIndicators);

}
Expand Up @@ -94,7 +94,8 @@ public BasicType<?> resolveType(
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() ) {
Expand Down
Expand Up @@ -145,7 +145,6 @@ public static class EntityOfByteArrays {
@Lob
private byte[] primitiveLob;
@Lob
@JavaType( ByteArrayJavaType.class )
private Byte[] wrapperLob;
//end::basic-bytearray-example[]

Expand Down
Expand Up @@ -119,7 +119,6 @@ public static class EntityWithCharArrays {
@Lob
char[] primitiveClob;
@Lob
@JavaType( CharacterArrayJavaType.class )
Character[] wrapperClob;
//end::basic-chararray-example[]
}
Expand Down
Expand Up @@ -132,7 +132,6 @@ public static class EntityWithCharArrays {
char[] primitiveNClob;
@Lob
@Nationalized
@JavaType( CharacterArrayJavaType.class )
Character[] wrapperNClob;
//end::basic-nchararray-example[]
}
Expand Down

0 comments on commit a35234a

Please sign in to comment.