Use VARCHAR registered JdbcType's type code instead of NationalizationSupport to fix HANA test issues

This commit is contained in:
Christian Beikov 2023-06-27 09:42:36 +02:00
parent c1c912d034
commit cbf5ee8e45
3 changed files with 13 additions and 21 deletions

View File

@ -6,14 +6,11 @@
*/ */
package org.hibernate.orm.test.annotations.embeddables.nested; package org.hibernate.orm.test.annotations.embeddables.nested;
import java.sql.Types;
import org.hibernate.boot.Metadata; import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources; import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.NationalizationSupport;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
@ -22,7 +19,7 @@ import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Value; import org.hibernate.mapping.Value;
import org.hibernate.type.SqlTypes; import org.hibernate.type.SqlTypes;
import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -45,9 +42,9 @@ public class NestedEmbeddableMetadataTest {
final Metadata metadata = new MetadataSources( serviceRegistry ) final Metadata metadata = new MetadataSources( serviceRegistry )
.addAnnotatedClass( Customer.class ) .addAnnotatedClass( Customer.class )
.buildMetadata(); .buildMetadata();
final NationalizationSupport nationalizationSupport = metadata.getDatabase() final JdbcTypeRegistry jdbcTypeRegistry = metadata.getDatabase()
.getDialect() .getTypeConfiguration()
.getNationalizationSupport(); .getJdbcTypeRegistry();
PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() ); PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() );
Property investmentsProperty = classMetadata.getProperty( "investments" ); Property investmentsProperty = classMetadata.getProperty( "investments" );
@ -62,7 +59,7 @@ public class NestedEmbeddableMetadataTest {
int[] currencySqlTypes = currencyMetadata.getType().getSqlTypeCodes( metadata ); int[] currencySqlTypes = currencyMetadata.getType().getSqlTypeCodes( metadata );
assertEquals(1, currencySqlTypes.length); assertEquals(1, currencySqlTypes.length);
assertJdbcTypeCode( assertJdbcTypeCode(
new int[] { nationalizationSupport.getVarcharVariantCode(), SqlTypes.ENUM }, new int[] { jdbcTypeRegistry.getDescriptor( SqlTypes.VARCHAR ).getJdbcTypeCode(), SqlTypes.ENUM },
currencySqlTypes[0] currencySqlTypes[0]
); );
} }

View File

@ -10,7 +10,6 @@ import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources; import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.dialect.NationalizationSupport;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column; import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
@ -19,6 +18,7 @@ import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Value; import org.hibernate.mapping.Value;
import org.hibernate.type.SqlTypes; import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -38,9 +38,9 @@ public class FieldAccessedNestedEmbeddableMetadataTest {
final Metadata metadata = new MetadataSources( ssr ) final Metadata metadata = new MetadataSources( ssr )
.addAnnotatedClass( Customer.class ) .addAnnotatedClass( Customer.class )
.buildMetadata(); .buildMetadata();
final NationalizationSupport nationalizationSupport = metadata.getDatabase() final JdbcTypeRegistry jdbcTypeRegistry = metadata.getDatabase()
.getDialect() .getTypeConfiguration()
.getNationalizationSupport(); .getJdbcTypeRegistry();
PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() ); PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() );
Property investmentsProperty = classMetadata.getProperty( "investments" ); Property investmentsProperty = classMetadata.getProperty( "investments" );
@ -55,7 +55,7 @@ public class FieldAccessedNestedEmbeddableMetadataTest {
int[] currencySqlTypes = currencyMetadata.getType().getSqlTypeCodes( metadata ); int[] currencySqlTypes = currencyMetadata.getType().getSqlTypeCodes( metadata );
assertEquals( 1, currencySqlTypes.length ); assertEquals( 1, currencySqlTypes.length );
assertJdbcTypeCode( assertJdbcTypeCode(
new int[] { nationalizationSupport.getVarcharVariantCode(), SqlTypes.ENUM }, new int[] { jdbcTypeRegistry.getDescriptor( SqlTypes.VARCHAR ).getJdbcTypeCode(), SqlTypes.ENUM },
currencySqlTypes[0] currencySqlTypes[0]
); );
} }

View File

@ -9,25 +9,24 @@ package org.hibernate.orm.test.mapping;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Types; import java.sql.Types;
import org.hibernate.dialect.NationalizationSupport;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping; import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
import org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping; import org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping;
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.ConvertedBasicType; import org.hibernate.type.ConvertedBasicType;
import org.hibernate.type.SqlTypes; import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter; import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.internal.BasicTypeImpl;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.type.internal.BasicTypeImpl;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -71,10 +70,6 @@ public class SmokeTests {
final JdbcTypeRegistry jdbcTypeRegistry = entityDescriptor.getFactory() final JdbcTypeRegistry jdbcTypeRegistry = entityDescriptor.getFactory()
.getTypeConfiguration() .getTypeConfiguration()
.getJdbcTypeRegistry(); .getJdbcTypeRegistry();
final NationalizationSupport nationalizationSupport = scope.getSessionFactory()
.getJdbcServices()
.getDialect()
.getNationalizationSupport();
final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping(); final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
assertThat( assertThat(
@ -127,7 +122,7 @@ public class SmokeTests {
assertThat( assertThat(
jdbcMapping.getJdbcType().getJdbcTypeCode(), jdbcMapping.getJdbcType().getJdbcTypeCode(),
isOneOf( SqlTypes.ENUM, nationalizationSupport.getVarcharVariantCode() ) isOneOf( SqlTypes.ENUM, jdbcTypeRegistry.getDescriptor( SqlTypes.VARCHAR ).getJdbcTypeCode() )
); );
} }