Fix tests for HANA

This commit is contained in:
Christian Beikov 2021-12-22 09:42:46 +01:00
parent dd0e65c698
commit 779cbef20c
17 changed files with 172 additions and 40 deletions

View File

@ -395,6 +395,7 @@ public abstract class AbstractStandardBasicType<T>
} }
break; break;
case Types.CHAR: case Types.CHAR:
case Types.NCHAR:
if ( getJavaType() == Boolean.class ) { if ( getJavaType() == Boolean.class ) {
return (Boolean) getJavaTypeDescriptor().wrap( 'Y', null ) return (Boolean) getJavaTypeDescriptor().wrap( 'Y', null )
? CastType.YN_BOOLEAN ? CastType.YN_BOOLEAN

View File

@ -21,6 +21,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.CustomType; import org.hibernate.type.CustomType;
import org.hibernate.type.spi.TypeConfiguration;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -43,6 +44,7 @@ public class NestedEmbeddableMetadataTest {
final Metadata metadata = new MetadataSources( serviceRegistry ) final Metadata metadata = new MetadataSources( serviceRegistry )
.addAnnotatedClass( Customer.class ) .addAnnotatedClass( Customer.class )
.buildMetadata(); .buildMetadata();
final TypeConfiguration typeConfiguration = metadata.getDatabase().getTypeConfiguration();
PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() ); PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() );
Property investmentsProperty = classMetadata.getProperty( "investments" ); Property investmentsProperty = classMetadata.getProperty( "investments" );
@ -57,7 +59,10 @@ public class NestedEmbeddableMetadataTest {
CustomType<Object> currencyType = (CustomType<Object>) currencyMetadata.getType(); CustomType<Object> currencyType = (CustomType<Object>) currencyMetadata.getType();
int[] currencySqlTypes = currencyType.getSqlTypeCodes( metadata ); int[] currencySqlTypes = currencyType.getSqlTypeCodes( metadata );
assertEquals( 1, currencySqlTypes.length ); assertEquals( 1, currencySqlTypes.length );
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] ); assertJdbcTypeCode(
typeConfiguration.getJdbcTypeDescriptorRegistry().getDescriptor( Types.VARCHAR ).getJdbcTypeCode(),
currencySqlTypes[0]
);
} }
finally { finally {
StandardServiceRegistryBuilder.destroy( serviceRegistry ); StandardServiceRegistryBuilder.destroy( serviceRegistry );

View File

@ -19,6 +19,8 @@ import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.type.CustomType; import org.hibernate.type.CustomType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
@ -60,22 +62,31 @@ public class EnumeratedSmokeTest extends BaseUnitTestCase {
.buildMetadata(); .buildMetadata();
mappings.validate(); mappings.validate();
final JdbcTypeRegistry jdbcTypeRegistry = mappings.getTypeConfiguration().getJdbcTypeDescriptorRegistry();
final PersistentClass entityBinding = mappings.getEntityBinding( EntityWithEnumeratedAttributes.class.getName() ); final PersistentClass entityBinding = mappings.getEntityBinding( EntityWithEnumeratedAttributes.class.getName() );
validateEnumMapping( entityBinding.getProperty( "notAnnotated" ), EnumType.ORDINAL ); validateEnumMapping( jdbcTypeRegistry, entityBinding.getProperty( "notAnnotated" ), EnumType.ORDINAL );
validateEnumMapping( entityBinding.getProperty( "noEnumType" ), EnumType.ORDINAL ); validateEnumMapping( jdbcTypeRegistry, entityBinding.getProperty( "noEnumType" ), EnumType.ORDINAL );
validateEnumMapping( entityBinding.getProperty( "ordinalEnumType" ), EnumType.ORDINAL ); validateEnumMapping( jdbcTypeRegistry, entityBinding.getProperty( "ordinalEnumType" ), EnumType.ORDINAL );
validateEnumMapping( entityBinding.getProperty( "stringEnumType" ), EnumType.STRING ); validateEnumMapping( jdbcTypeRegistry, entityBinding.getProperty( "stringEnumType" ), EnumType.STRING );
} }
private void validateEnumMapping(Property property, EnumType expectedJpaEnumType) { private void validateEnumMapping(JdbcTypeRegistry jdbcRegistry, Property property, EnumType expectedJpaEnumType) {
assertThat( property.getType(), instanceOf( CustomType.class ) ); assertThat( property.getType(), instanceOf( CustomType.class ) );
final CustomType<Object> customType = (CustomType<Object>) property.getType(); final CustomType<Object> customType = (CustomType<Object>) property.getType();
assertThat( customType.getUserType(), instanceOf( org.hibernate.type.EnumType.class ) ); assertThat( customType.getUserType(), instanceOf( org.hibernate.type.EnumType.class ) );
final org.hibernate.type.EnumType hibernateMappingEnumType = (org.hibernate.type.EnumType) customType.getUserType(); final org.hibernate.type.EnumType hibernateMappingEnumType = (org.hibernate.type.EnumType) customType.getUserType();
assertThat( hibernateMappingEnumType.isOrdinal(), is(expectedJpaEnumType==EnumType.ORDINAL) ); assertThat( hibernateMappingEnumType.isOrdinal(), is(expectedJpaEnumType==EnumType.ORDINAL) );
assertThat( hibernateMappingEnumType.sqlTypes().length, is(1) ); assertThat( hibernateMappingEnumType.sqlTypes().length, is(1) );
assertThat( hibernateMappingEnumType.sqlTypes()[0], is(expectedJpaEnumType==EnumType.ORDINAL? Types.TINYINT:Types.VARCHAR) ); final int expectedJdbcTypeCode = jdbcRegistry.getDescriptor(
expectedJpaEnumType == EnumType.ORDINAL ?
Types.TINYINT :
Types.VARCHAR
).getJdbcTypeCode();
assertThat(
hibernateMappingEnumType.sqlTypes()[0],
is( expectedJdbcTypeCode )
);
} }
@Entity @Entity

View File

@ -2,11 +2,15 @@ package org.hibernate.orm.test.insertordering;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types;
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.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider; import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest; import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest;
@ -59,6 +63,18 @@ abstract class BaseInsertOrderingTest extends BaseSessionFactoryFunctionalTest {
connectionProvider.stop(); connectionProvider.stop();
} }
protected String literal(String value) {
final JdbcType jdbcType = sessionFactory().getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor(
Types.VARCHAR
);
return jdbcType.getJdbcLiteralFormatter( StringJavaTypeDescriptor.INSTANCE )
.toJdbcLiteral(
value,
sessionFactory().getJdbcServices().getDialect(),
sessionFactory().getWrapperOptions()
);
}
void verifyContainsBatches(Batch... expectedBatches) { void verifyContainsBatches(Batch... expectedBatches) {
for ( Batch expectedBatch : expectedBatches ) { for ( Batch expectedBatch : expectedBatches ) {
PreparedStatement preparedStatement = connectionProvider.getPreparedStatement( expectedBatch.sql ); PreparedStatement preparedStatement = connectionProvider.getPreparedStatement( expectedBatch.sql );

View File

@ -1,5 +1,6 @@
package org.hibernate.orm.test.insertordering; package org.hibernate.orm.test.insertordering;
import java.sql.Types;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import jakarta.persistence.CascadeType; import jakarta.persistence.CascadeType;
@ -21,6 +22,8 @@ import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode; import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.SortNatural; import org.hibernate.annotations.SortNatural;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -70,8 +73,8 @@ public class InsertOrderingSelfReferenceTest extends BaseInsertOrderingTest {
verifyContainsBatches( verifyContainsBatches(
new Batch( "insert into Placeholder (name, id) values (?, ?)", 2 ), new Batch( "insert into Placeholder (name, id) values (?, ?)", 2 ),
new Batch( "insert into Parameter (name, parent_id, TYPE, id) values (?, ?, 'INPUT', ?)" ), new Batch( "insert into Parameter (name, parent_id, TYPE, id) values (?, ?, " + literal( "INPUT" ) + ", ?)" ),
new Batch( "insert into Parameter (name, parent_id, TYPE, id) values (?, ?, 'OUTPUT', ?)", 3 ) new Batch( "insert into Parameter (name, parent_id, TYPE, id) values (?, ?, " + literal( "OUTPUT" ) + ", ?)", 3 )
); );
} }

View File

@ -73,8 +73,8 @@ public class InsertOrderingWithSecondaryTable extends BaseInsertOrderingTest {
verifyContainsBatches( verifyContainsBatches(
new Batch( "insert into TOP_LEVEL (name, id) values (?, ?)" ), new Batch( "insert into TOP_LEVEL (name, id) values (?, ?)" ),
new Batch( "insert into SHAPE (name, SHAPE_TYPE, SHAPE_ID) values (?, 'POLYGON', ?)" ), new Batch( "insert into SHAPE (name, SHAPE_TYPE, SHAPE_ID) values (?, " + literal( "POLYGON" ) + ", ?)" ),
new Batch( "insert into SHAPE (name, SHAPE_TYPE, SHAPE_ID) values (?, 'CIRCLE', ?)" ), new Batch( "insert into SHAPE (name, SHAPE_TYPE, SHAPE_ID) values (?, " + literal( "CIRCLE" ) + ", ?)" ),
new Batch( "insert into SHAPE_CIRCLE (centre, SHAPE_ID) values (?, ?)" ), new Batch( "insert into SHAPE_CIRCLE (centre, SHAPE_ID) values (?, ?)" ),
new Batch( "insert into GEOGRAPHIC_AREA (name, SHAPE_ID, TOP_LEVEL_ID, id) values (?, ?, ?, ?)", 2 ) new Batch( "insert into GEOGRAPHIC_AREA (name, SHAPE_ID, TOP_LEVEL_ID, id) values (?, ?, ?, ?)", 2 )
); );

View File

@ -10,6 +10,8 @@ import java.sql.Types;
import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope; import org.hibernate.testing.orm.junit.DomainModelScope;
@ -31,10 +33,14 @@ public class SimpleAttributeBinderTests {
assertThat( activeMapping.getJpaAttributeConverterDescriptor() ).isNotNull(); assertThat( activeMapping.getJpaAttributeConverterDescriptor() ).isNotNull();
final BasicValue.Resolution<?> resolution = activeMapping.resolve(); final BasicValue.Resolution<?> resolution = activeMapping.resolve();
final JdbcTypeRegistry jdbcTypeRegistry = activeMapping.getBuildingContext()
.getBuildingOptions()
.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
assertThat( resolution.getDomainJavaDescriptor().getJavaType() ).isEqualTo( Boolean.class ); assertThat( resolution.getDomainJavaDescriptor().getJavaType() ).isEqualTo( Boolean.class );
assertThat( resolution.getRelationalJavaDescriptor().getJavaType() ).isEqualTo( Character.class ); assertThat( resolution.getRelationalJavaDescriptor().getJavaType() ).isEqualTo( Character.class );
assertThat( resolution.getJdbcTypeDescriptor().getJdbcTypeCode() ).isEqualTo( Types.CHAR ); assertThat( resolution.getJdbcTypeDescriptor() ).isEqualTo( jdbcTypeRegistry.getDescriptor( Types.CHAR ) );
assertThat( resolution.getValueConverter() ).isNotNull(); assertThat( resolution.getValueConverter() ).isNotNull();
} ); } );
} }

View File

@ -19,6 +19,7 @@ import org.hibernate.boot.internal.ClassmateContext;
import org.hibernate.boot.model.convert.internal.InstanceBasedConverterDescriptor; import org.hibernate.boot.model.convert.internal.InstanceBasedConverterDescriptor;
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.boot.spi.MetadataBuildingContext;
import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
@ -37,6 +38,8 @@ import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
import org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor; import org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor;
import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor; import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcType; import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl; import org.hibernate.testing.boot.MetadataBuildingContextTestingImpl;
@ -110,7 +113,11 @@ public class AttributeConverterTest extends BaseUnitTestCase {
@Test @Test
public void testBasicOperation() { public void testBasicOperation() {
try ( StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) { try ( StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
final BasicValue basicValue = new BasicValue( new MetadataBuildingContextTestingImpl( serviceRegistry ) ); final MetadataBuildingContext buildingContext = new MetadataBuildingContextTestingImpl( serviceRegistry );
final JdbcTypeRegistry jdbcTypeRegistry = buildingContext.getBootstrapContext()
.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
final BasicValue basicValue = new BasicValue( buildingContext );
basicValue.setJpaAttributeConverterDescriptor( basicValue.setJpaAttributeConverterDescriptor(
new InstanceBasedConverterDescriptor( new InstanceBasedConverterDescriptor(
new StringClobConverter(), new StringClobConverter(),
@ -128,7 +135,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) ); assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( String.class ) );
final JdbcType jdbcType = typeAdapter.getJdbcTypeDescriptor(); final JdbcType jdbcType = typeAdapter.getJdbcTypeDescriptor();
assertThat( jdbcType.getJdbcTypeCode(), is( Types.CLOB ) ); assertThat( jdbcType, is( jdbcTypeRegistry.getDescriptor( Types.CLOB ) ) );
} }
} }
@ -168,6 +175,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
.getMetadataBuilder() .getMetadataBuilder()
.applyAttributeConverter( StringClobConverter.class, true ) .applyAttributeConverter( StringClobConverter.class, true )
.build(); .build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
final PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); final PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
final Property nameProp = tester.getProperty( "name" ); final Property nameProp = tester.getProperty( "name" );
@ -180,7 +189,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type; final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), Matchers.equalTo( String.class ) ); assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), Matchers.equalTo( String.class ) );
final JdbcType jdbcType = typeAdapter.getJdbcTypeDescriptor(); final JdbcType jdbcType = typeAdapter.getJdbcTypeDescriptor();
assertThat( jdbcType.getJdbcTypeCode(), is( Types.CLOB ) ); assertThat( jdbcType, is( jdbcTypeRegistry.getDescriptor( Types.CLOB ) ) );
} }
finally { finally {
StandardServiceRegistryBuilder.destroy( ssr ); StandardServiceRegistryBuilder.destroy( ssr );
@ -198,6 +207,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
.addURL( ConfigHelper.findAsResource( "org/hibernate/test/converter/orm.xml" ) ) .addURL( ConfigHelper.findAsResource( "org/hibernate/test/converter/orm.xml" ) )
.getMetadataBuilder() .getMetadataBuilder()
.build(); .build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
Property nameProp = tester.getProperty( "name" ); Property nameProp = tester.getProperty( "name" );
@ -212,7 +223,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( Clob.class ) ); assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( Clob.class ) );
final JdbcType jdbcType = typeAdapter.getJdbcTypeDescriptor(); final JdbcType jdbcType = typeAdapter.getJdbcTypeDescriptor();
assertThat( jdbcType.getJdbcTypeCode(), is( Types.CLOB ) ); assertThat( jdbcType, is( jdbcTypeRegistry.getDescriptor( Types.CLOB ) ) );
} }
finally { finally {
StandardServiceRegistryBuilder.destroy( ssr ); StandardServiceRegistryBuilder.destroy( ssr );
@ -230,6 +241,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
.addURL( ConfigHelper.findAsResource( "org/hibernate/test/converter/package.xml" ) ) .addURL( ConfigHelper.findAsResource( "org/hibernate/test/converter/package.xml" ) )
.getMetadataBuilder() .getMetadataBuilder()
.build(); .build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() ); PersistentClass tester = metadata.getEntityBinding( Tester.class.getName() );
Property nameProp = tester.getProperty( "name" ); Property nameProp = tester.getProperty( "name" );
@ -246,7 +259,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( Clob.class ) ); assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( Clob.class ) );
final JdbcType sqlTypeDescriptor = typeAdapter.getJdbcTypeDescriptor(); final JdbcType sqlTypeDescriptor = typeAdapter.getJdbcTypeDescriptor();
assertThat( sqlTypeDescriptor.getJdbcTypeCode(), is( Types.CLOB ) ); assertThat( sqlTypeDescriptor, is( jdbcTypeRegistry.getDescriptor( Types.CLOB ) ) );
} }
finally { finally {
StandardServiceRegistryBuilder.destroy( ssr ); StandardServiceRegistryBuilder.destroy( ssr );
@ -264,6 +277,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
.getMetadataBuilder() .getMetadataBuilder()
.applyAttributeConverter( StringClobConverter.class, true ) .applyAttributeConverter( StringClobConverter.class, true )
.build(); .build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
PersistentClass tester = metadata.getEntityBinding( Tester2.class.getName() ); PersistentClass tester = metadata.getEntityBinding( Tester2.class.getName() );
Property nameProp = tester.getProperty( "name" ); Property nameProp = tester.getProperty( "name" );
@ -275,7 +290,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
} }
AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type ); AbstractStandardBasicType basicType = assertTyping( AbstractStandardBasicType.class, type );
assertSame( StringJavaTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() ); assertSame( StringJavaTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor() );
assertEquals( Types.VARCHAR, basicType.getJdbcTypeDescriptor().getJdbcTypeCode() ); assertEquals( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ), basicType.getJdbcTypeDescriptor() );
} }
finally { finally {
StandardServiceRegistryBuilder.destroy( ssr ); StandardServiceRegistryBuilder.destroy( ssr );
@ -333,6 +348,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
.getMetadataBuilder() .getMetadataBuilder()
.applyAttributeConverter( IntegerToVarcharConverter.class, true ) .applyAttributeConverter( IntegerToVarcharConverter.class, true )
.build(); .build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
final PersistentClass tester = metadata.getEntityBinding( Tester5.class.getName() ); final PersistentClass tester = metadata.getEntityBinding( Tester5.class.getName() );
final Property codeProp = tester.getProperty( "code" ); final Property codeProp = tester.getProperty( "code" );
@ -345,7 +362,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( Integer.class ) ); assertThat( typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo( Integer.class ) );
assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( String.class ) ); assertThat( typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo( String.class ) );
assertThat( typeAdapter.getJdbcTypeDescriptor().getJdbcTypeCode(), is( Types.VARCHAR ) ); assertThat( typeAdapter.getJdbcTypeDescriptor(), is( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ) ) );
} }
finally { finally {
StandardServiceRegistryBuilder.destroy( ssr ); StandardServiceRegistryBuilder.destroy( ssr );
@ -437,6 +454,8 @@ public class AttributeConverterTest extends BaseUnitTestCase {
.getMetadataBuilder() .getMetadataBuilder()
.applyAttributeConverter( ConvertibleEnumConverter.class, true ) .applyAttributeConverter( ConvertibleEnumConverter.class, true )
.build(); .build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
// first lets validate that the converter was applied... // first lets validate that the converter was applied...
final PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() ); final PersistentClass tester = metadata.getEntityBinding( EntityWithConvertibleField.class.getName() );
@ -459,7 +478,7 @@ public class AttributeConverterTest extends BaseUnitTestCase {
else { else {
expectedJdbcTypeCode = Types.VARCHAR; expectedJdbcTypeCode = Types.VARCHAR;
} }
assertThat( typeAdapter.getJdbcTypeDescriptor().getJdbcTypeCode(), is( expectedJdbcTypeCode ) ); assertThat( typeAdapter.getJdbcTypeDescriptor(), is( jdbcTypeRegistry.getDescriptor( expectedJdbcTypeCode ) ) );
// then lets build the SF and verify its use... // then lets build the SF and verify its use...
final SessionFactory sf = metadata.buildSessionFactory(); final SessionFactory sf = metadata.buildSessionFactory();

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.orm.test.mapping.converted.converter; package org.hibernate.orm.test.mapping.converted.converter;
import java.sql.Types;
import jakarta.persistence.Convert; import jakarta.persistence.Convert;
import jakarta.persistence.Embeddable; import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded; import jakarta.persistence.Embedded;
@ -18,6 +20,7 @@ import org.hibernate.type.CompositeType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor; import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; import org.hibernate.type.descriptor.jdbc.VarcharJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
@ -46,10 +49,12 @@ public class SimpleEmbeddableOverriddenConverterTest extends BaseNonConfigCoreFu
@Test @Test
public void testSimpleConvertOverrides() { public void testSimpleConvertOverrides() {
final EntityPersister ep = sessionFactory().getEntityPersister( Person.class.getName() ); final EntityPersister ep = sessionFactory().getEntityPersister( Person.class.getName() );
final JdbcTypeRegistry jdbcTypeRegistry = sessionFactory().getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
CompositeType homeAddressType = assertTyping( CompositeType.class, ep.getPropertyType( "homeAddress" ) ); CompositeType homeAddressType = assertTyping( CompositeType.class, ep.getPropertyType( "homeAddress" ) );
BasicType<?> homeAddressCityType = (BasicType<?>) findCompositeAttributeType( homeAddressType, "city" ); BasicType<?> homeAddressCityType = (BasicType<?>) findCompositeAttributeType( homeAddressType, "city" );
assertTyping( StringJavaTypeDescriptor.class, homeAddressCityType.getJavaTypeDescriptor() ); assertTyping( StringJavaTypeDescriptor.class, homeAddressCityType.getJavaTypeDescriptor() );
assertTyping( VarcharJdbcType.class, homeAddressCityType.getJdbcTypeDescriptor() ); assertTyping( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ).getClass(), homeAddressCityType.getJdbcTypeDescriptor() );
} }
public Type findCompositeAttributeType(CompositeType compositeType, String attributeName) { public Type findCompositeAttributeType(CompositeType compositeType, String attributeName) {

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.orm.test.mapping.converted.converter; package org.hibernate.orm.test.mapping.converted.converter;
import java.sql.Types;
import jakarta.persistence.Convert; import jakarta.persistence.Convert;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -15,6 +17,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor; import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; import org.hibernate.type.descriptor.jdbc.VarcharJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
@ -43,10 +46,12 @@ public class SimpleOverriddenConverterTest extends BaseNonConfigCoreFunctionalTe
@Test @Test
public void testSimpleConvertOverrides() { public void testSimpleConvertOverrides() {
final EntityPersister ep = sessionFactory().getEntityPersister( Sub.class.getName() ); final EntityPersister ep = sessionFactory().getEntityPersister( Sub.class.getName() );
final JdbcTypeRegistry jdbcTypeRegistry = sessionFactory().getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
BasicType<?> type = (BasicType<?>) ep.getPropertyType( "it" ); BasicType<?> type = (BasicType<?>) ep.getPropertyType( "it" );
assertTyping( StringJavaTypeDescriptor.class, type.getJavaTypeDescriptor() ); assertTyping( StringJavaTypeDescriptor.class, type.getJavaTypeDescriptor() );
assertTyping( VarcharJdbcType.class, type.getJdbcTypeDescriptor() ); assertTyping( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ).getClass(), type.getJdbcTypeDescriptor() );
} }
@MappedSuperclass @MappedSuperclass

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.orm.test.mapping.converted.converter; package org.hibernate.orm.test.mapping.converted.converter;
import java.sql.Types;
import jakarta.persistence.Convert; import jakarta.persistence.Convert;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -20,6 +22,7 @@ import org.hibernate.type.Type;
import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter; import org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter;
import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor; import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; import org.hibernate.type.descriptor.jdbc.VarcharJdbcType;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.After; import org.junit.After;
@ -74,11 +77,13 @@ public class SimpleXmlOverriddenTest extends BaseUnitTestCase {
.addAnnotatedClass( TheEntity.class ) .addAnnotatedClass( TheEntity.class )
.addResource( "org/hibernate/test/converter/simple-override.xml" ) .addResource( "org/hibernate/test/converter/simple-override.xml" )
.buildMetadata(); .buildMetadata();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getDatabase().getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
PersistentClass pc = metadata.getEntityBinding( TheEntity.class.getName() ); PersistentClass pc = metadata.getEntityBinding( TheEntity.class.getName() );
BasicType<?> type = (BasicType<?>) pc.getProperty( "it" ).getType(); BasicType<?> type = (BasicType<?>) pc.getProperty( "it" ).getType();
assertTyping( StringJavaTypeDescriptor.class, type.getJavaTypeDescriptor() ); assertTyping( StringJavaTypeDescriptor.class, type.getJavaTypeDescriptor() );
assertTyping( VarcharJdbcType.class, type.getJdbcTypeDescriptor() ); assertTyping( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ).getClass(), type.getJdbcTypeDescriptor() );
} }
/** /**
@ -91,11 +96,13 @@ public class SimpleXmlOverriddenTest extends BaseUnitTestCase {
.addAnnotatedClass( TheEntity2.class ) .addAnnotatedClass( TheEntity2.class )
.addResource( "org/hibernate/test/converter/simple-override2.xml" ) .addResource( "org/hibernate/test/converter/simple-override2.xml" )
.buildMetadata(); .buildMetadata();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getDatabase().getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
PersistentClass pc = metadata.getEntityBinding( TheEntity2.class.getName() ); PersistentClass pc = metadata.getEntityBinding( TheEntity2.class.getName() );
BasicType<?> type = (BasicType<?>) pc.getProperty( "it" ).getType(); BasicType<?> type = (BasicType<?>) pc.getProperty( "it" ).getType();
assertTyping( StringJavaTypeDescriptor.class, type.getJavaTypeDescriptor() ); assertTyping( StringJavaTypeDescriptor.class, type.getJavaTypeDescriptor() );
assertTyping( VarcharJdbcType.class, type.getJdbcTypeDescriptor() ); assertTyping( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ).getClass(), type.getJdbcTypeDescriptor() );
} }
@Entity(name="TheEntity") @Entity(name="TheEntity")

View File

@ -6,19 +6,28 @@
*/ */
package org.hibernate.orm.test.mapping.converted.converter.custom; package org.hibernate.orm.test.mapping.converted.converter.custom;
import java.util.List;
import org.hibernate.boot.MetadataSources; import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
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.boot.spi.InFlightMetadataCollector;
import org.hibernate.boot.spi.MetadataBuilderImplementor; import org.hibernate.boot.spi.MetadataBuilderImplementor;
import org.hibernate.boot.spi.MetadataContributor;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.tool.schema.Action; import org.hibernate.tool.schema.Action;
import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.testing.boot.ExtraJavaServicesClassLoaderService;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test; import org.junit.Test;
import org.jboss.jandex.IndexView;
import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
@ -28,8 +37,16 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class CustomTypeConverterTest extends BaseUnitTestCase { public class CustomTypeConverterTest extends BaseUnitTestCase {
@Test @Test
public void testConverterAppliedScopedRegistration() { public void testConverterAppliedScopedRegistration() {
final List<ExtraJavaServicesClassLoaderService.JavaServiceDescriptor<?>> services = List.of(
try ( final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() new ExtraJavaServicesClassLoaderService.JavaServiceDescriptor<>(
MetadataContributor.class,
PayloadWrapperMetadataContributor.class
)
);
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().enableAutoClose()
.applyClassLoaderService( new ExtraJavaServicesClassLoaderService( services ) )
.build();
try ( final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ) .applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
.build() ) { .build() ) {
final MetadataSources metadataSources = new MetadataSources( ssr ) final MetadataSources metadataSources = new MetadataSources( ssr )
@ -39,10 +56,6 @@ public class CustomTypeConverterTest extends BaseUnitTestCase {
// now the new scoped way // now the new scoped way
final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration(); final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration();
bootTypeConfiguration.getJavaTypeDescriptorRegistry()
.addDescriptor( PayloadWrapperJavaType.INSTANCE );
bootTypeConfiguration.getJdbcTypeDescriptorRegistry()
.addDescriptor( PayloadWrapperJdbcType.INSTANCE );
performAssertions( metadataBuilder, bootTypeConfiguration ); performAssertions( metadataBuilder, bootTypeConfiguration );
} }
@ -71,4 +84,15 @@ public class CustomTypeConverterTest extends BaseUnitTestCase {
entityPersister.getPropertyType( "customType" ); entityPersister.getPropertyType( "customType" );
} }
} }
public static class PayloadWrapperMetadataContributor implements MetadataContributor {
@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
final TypeConfiguration typeConfiguration = metadataCollector.getTypeConfiguration();
typeConfiguration.getJavaTypeDescriptorRegistry()
.addDescriptor( PayloadWrapperJavaType.INSTANCE );
typeConfiguration.getJdbcTypeDescriptorRegistry()
.addDescriptor( PayloadWrapperJdbcType.INSTANCE );
}
}
} }

View File

@ -14,6 +14,7 @@ import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Formula; import org.hibernate.mapping.Formula;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope; import org.hibernate.testing.orm.junit.DomainModelScope;
@ -37,11 +38,14 @@ public class FormulaFromHbmTests {
scope.withHierarchy( scope.withHierarchy(
EntityOfFormulas.class, EntityOfFormulas.class,
(rootClass) -> { (rootClass) -> {
final JdbcTypeRegistry jdbcTypeRegistry = scope.getDomainModel()
.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
final Property stringFormula = rootClass.getProperty( "stringFormula" ); final Property stringFormula = rootClass.getProperty( "stringFormula" );
{ {
final int[] sqlTypes = stringFormula.getType().getSqlTypeCodes( scope.getDomainModel() ); final int[] sqlTypes = stringFormula.getType().getSqlTypeCodes( scope.getDomainModel() );
assertThat( sqlTypes.length, is( 1 ) ); assertThat( sqlTypes.length, is( 1 ) );
assertThat( sqlTypes[ 0 ], is( Types.VARCHAR ) ); assertThat( sqlTypes[ 0 ], is( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ).getJdbcTypeCode() ) );
final Selectable selectable = ( (BasicValue) stringFormula.getValue() ).getColumn(); final Selectable selectable = ( (BasicValue) stringFormula.getValue() ).getColumn();
assertThat( selectable, instanceOf( Formula.class ) ); assertThat( selectable, instanceOf( Formula.class ) );
@ -51,7 +55,7 @@ public class FormulaFromHbmTests {
{ {
final int[] sqlTypes = integerFormula.getType().getSqlTypeCodes( scope.getDomainModel() ); final int[] sqlTypes = integerFormula.getType().getSqlTypeCodes( scope.getDomainModel() );
assertThat( sqlTypes.length, is( 1 ) ); assertThat( sqlTypes.length, is( 1 ) );
assertThat( sqlTypes[ 0 ], is( Types.INTEGER ) ); assertThat( sqlTypes[ 0 ], is( jdbcTypeRegistry.getDescriptor( Types.INTEGER ).getJdbcTypeCode() ) );
final Selectable selectable = ( (BasicValue) integerFormula.getValue() ).getColumn(); final Selectable selectable = ( (BasicValue) integerFormula.getValue() ).getColumn();
assertThat( selectable, instanceOf( Formula.class ) ); assertThat( selectable, instanceOf( Formula.class ) );

View File

@ -16,6 +16,7 @@ import java.util.Set;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
@ -43,16 +44,17 @@ public class ZoneMappingTests {
public void basicAssertions(SessionFactoryScope scope) { public void basicAssertions(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory(); final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final EntityPersister entityDescriptor = sessionFactory.getMetamodel().entityPersister( ZoneMappingTestEntity.class ); final EntityPersister entityDescriptor = sessionFactory.getMetamodel().entityPersister( ZoneMappingTestEntity.class );
final JdbcTypeRegistry jdbcTypeRegistry = sessionFactory.getTypeConfiguration().getJdbcTypeDescriptorRegistry();
{ {
final BasicAttributeMapping zoneIdAttribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "zoneId" ); final BasicAttributeMapping zoneIdAttribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "zoneId" );
assertThat( zoneIdAttribute.getJdbcMapping().getJdbcTypeDescriptor().getJdbcTypeCode() ).isEqualTo( Types.VARCHAR ); assertThat( zoneIdAttribute.getJdbcMapping().getJdbcTypeDescriptor() ).isEqualTo( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ) );
assertThat( zoneIdAttribute.getJdbcMapping().getJavaTypeDescriptor().getJavaTypeClass() ).isEqualTo( ZoneId.class ); assertThat( zoneIdAttribute.getJdbcMapping().getJavaTypeDescriptor().getJavaTypeClass() ).isEqualTo( ZoneId.class );
} }
{ {
final BasicAttributeMapping zoneOffsetAttribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "zoneOffset" ); final BasicAttributeMapping zoneOffsetAttribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "zoneOffset" );
assertThat( zoneOffsetAttribute.getJdbcMapping().getJdbcTypeDescriptor().getJdbcTypeCode() ).isEqualTo( Types.VARCHAR ); assertThat( zoneOffsetAttribute.getJdbcMapping().getJdbcTypeDescriptor() ).isEqualTo( jdbcTypeRegistry.getDescriptor( Types.VARCHAR ) );
assertThat( zoneOffsetAttribute.getJdbcMapping().getJavaTypeDescriptor().getJavaTypeClass() ).isEqualTo( ZoneOffset.class ); assertThat( zoneOffsetAttribute.getJdbcMapping().getJavaTypeDescriptor().getJavaTypeClass() ).isEqualTo( ZoneOffset.class );
} }
} }

View File

@ -7,6 +7,7 @@
package org.hibernate.orm.test.query; package org.hibernate.orm.test.query;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Types;
import java.util.Map; import java.util.Map;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Id; import jakarta.persistence.Id;
@ -18,6 +19,8 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.jpa.QueryHints; import org.hibernate.jpa.QueryHints;
import org.hibernate.query.NativeQuery; import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.testing.DialectChecks; import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature; import org.hibernate.testing.RequiresDialectFeature;
@ -44,6 +47,8 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
); );
private static final String QUERY = "update AnEntity set name='abc'"; private static final String QUERY = "update AnEntity set name='abc'";
private String expectedSqlQuery;
@Override @Override
protected Class[] getAnnotatedClasses() { protected Class[] getAnnotatedClasses() {
return new Class[] { AnEntity.class }; return new Class[] { AnEntity.class };
@ -58,6 +63,15 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
@Before @Before
public void before() { public void before() {
CONNECTION_PROVIDER.clear(); CONNECTION_PROVIDER.clear();
final JdbcType jdbcType = sessionFactory().getTypeConfiguration().getJdbcTypeDescriptorRegistry().getDescriptor(
Types.VARCHAR
);
expectedSqlQuery = "update AnEntity set name=" + jdbcType.getJdbcLiteralFormatter( StringJavaTypeDescriptor.INSTANCE )
.toJdbcLiteral(
"abc",
sessionFactory().getJdbcServices().getDialect(),
sessionFactory().getWrapperOptions()
);
} }
@Test @Test
@ -79,7 +93,7 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
} }
else { else {
verify( verify(
CONNECTION_PROVIDER.getPreparedStatement( QUERY ), CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ),
times( 1 ) times( 1 )
).setQueryTimeout( 123 ); ).setQueryTimeout( 123 );
} }
@ -110,7 +124,7 @@ public class QueryTimeOutTest extends BaseNonConfigCoreFunctionalTestCase {
} }
else { else {
verify( verify(
CONNECTION_PROVIDER.getPreparedStatement( QUERY ), CONNECTION_PROVIDER.getPreparedStatement( expectedSqlQuery ),
times( 1 ) times( 1 )
).setQueryTimeout( 123 ); ).setQueryTimeout( 123 );
} }

View File

@ -23,6 +23,7 @@ import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
import org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter; import org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter;
import org.hibernate.query.sql.spi.NativeQueryImplementor; import org.hibernate.query.sql.spi.NativeQueryImplementor;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.orm.domain.StandardDomainModel; import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.domain.gambit.EntityOfBasics; import org.hibernate.testing.orm.domain.gambit.EntityOfBasics;
@ -283,7 +284,9 @@ public class NativeQueryResultBuilderTests {
final EntityMappingType entityDescriptor = scope.getSessionFactory() final EntityMappingType entityDescriptor = scope.getSessionFactory()
.getRuntimeMetamodels() .getRuntimeMetamodels()
.getEntityMappingType( EntityOfBasics.class ); .getEntityMappingType( EntityOfBasics.class );
final JdbcTypeRegistry jdbcTypeRegistry = scope.getSessionFactory()
.getTypeConfiguration()
.getJdbcTypeDescriptorRegistry();
final ModelPart part = entityDescriptor.findSubPart( "convertedGender", null ); final ModelPart part = entityDescriptor.findSubPart( "convertedGender", null );
assertThat( part, instanceOf( BasicAttributeMapping.class ) ); assertThat( part, instanceOf( BasicAttributeMapping.class ) );
final BasicAttributeMapping attrMapping = (BasicAttributeMapping) part; final BasicAttributeMapping attrMapping = (BasicAttributeMapping) part;
@ -295,7 +298,7 @@ public class NativeQueryResultBuilderTests {
assertThat( valueConverter.getDomainJavaDescriptor(), is( attrMapping.getJavaTypeDescriptor() ) ); assertThat( valueConverter.getDomainJavaDescriptor(), is( attrMapping.getJavaTypeDescriptor() ) );
assertThat( valueConverter.getRelationalJavaDescriptor().getJavaTypeClass(), equalTo( Character.class ) ); assertThat( valueConverter.getRelationalJavaDescriptor().getJavaTypeClass(), equalTo( Character.class ) );
assertThat( attrMapping.getJdbcMapping().getJdbcTypeDescriptor().getJdbcTypeCode(), is( Types.CHAR ) ); assertThat( attrMapping.getJdbcMapping().getJdbcTypeDescriptor(), is( jdbcTypeRegistry.getDescriptor( Types.CHAR ) ) );
} }
@BeforeEach @BeforeEach

View File

@ -22,6 +22,7 @@ import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.dialect.Dialect;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport; import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType; import org.hibernate.tool.schema.TargetType;
@ -68,8 +69,14 @@ public class HANASchemaMigrationTargetScriptCreationTest extends BaseCoreFunctio
this.output.deleteOnExit(); this.output.deleteOnExit();
configuration.setProperty( Environment.HBM2DDL_SCRIPTS_ACTION, "create" ); configuration.setProperty( Environment.HBM2DDL_SCRIPTS_ACTION, "create" );
configuration.setProperty( Environment.HBM2DDL_SCRIPTS_CREATE_TARGET, this.output.getAbsolutePath() ); configuration.setProperty( Environment.HBM2DDL_SCRIPTS_CREATE_TARGET, this.output.getAbsolutePath() );
this.varcharType = ( (AbstractHANADialect) getDialect() ).isUseUnicodeStringTypes() ? "nvarchar" : "varchar"; }
this.clobType = ( (AbstractHANADialect) getDialect() ).isUseUnicodeStringTypes() ? "nclob" : "clob";
@Override
protected void afterSessionFactoryBuilt() {
super.afterSessionFactoryBuilt();
final Dialect dialect = sessionFactory().getJdbcServices().getDialect();
this.varcharType = ( (AbstractHANADialect) dialect ).isUseUnicodeStringTypes() ? "nvarchar" : "varchar";
this.clobType = ( (AbstractHANADialect) dialect ).isUseUnicodeStringTypes() ? "nclob" : "clob";
} }
@After @After