HHH-16591 - Default JdbcType should be looked up by Duration class type, not by INTERVAL_SECOND

This commit is contained in:
Cedomir Igaly 2023-05-13 17:52:06 +02:00 committed by Christian Beikov
parent c1ecd20850
commit 049f24d67a
1 changed files with 10 additions and 7 deletions

View File

@ -47,30 +47,33 @@ public class PostgresIntervalSecondTest {
PostgresIntervalSecondTest.EntityWithIntervalSecondDuration.class ); PostgresIntervalSecondTest.EntityWithIntervalSecondDuration.class );
final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry(); final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
final JdbcType durationJdbcType = mappingMetamodel.getTypeConfiguration()
final JdbcType intervalType = jdbcTypeRegistry.getDescriptor( SqlTypes.INTERVAL_SECOND ); .getBasicTypeForJavaType( Duration.class )
.getJdbcType();
// default interval type set by a config property and should be `NUMERIC` // default interval type set by a config property and should be `NUMERIC`
assertThat( intervalType ).isEqualTo( NumericJdbcType.INSTANCE ); assertThat( durationJdbcType ).isEqualTo( NumericJdbcType.INSTANCE );
final JdbcType intervalType = jdbcTypeRegistry.getDescriptor( SqlTypes.INTERVAL_SECOND );
assertThat( intervalType ).isOfAnyClassIn( PostgreSQLIntervalSecondJdbcType.class );
// a simple duration field with no overrides - so should be using a default JdbcType // a simple duration field with no overrides - so should be using a default JdbcType
assertThat( entityDescriptor.findAttributeMapping( "duration" ) assertThat( entityDescriptor.findAttributeMapping( "duration" )
.getSingleJdbcMapping().getJdbcType() ) .getSingleJdbcMapping().getJdbcType() )
.isEqualTo( intervalType ); .isEqualTo( durationJdbcType );
// a field that is using a @JdbcType annotation to override the JdbcType. Hence, the used JdbcType must match the one // a field that is using a @JdbcType annotation to override the JdbcType. Hence, the used JdbcType must match the one
// set by the annotation. // set by the annotation.
assertThat( entityDescriptor.findAttributeMapping( "durationJdbcType" ) assertThat( entityDescriptor.findAttributeMapping( "durationJdbcType" )
.getSingleJdbcMapping().getJdbcType() ) .getSingleJdbcMapping().getJdbcType() )
.isNotEqualTo( intervalType ) .isNotEqualTo( durationJdbcType )
.isOfAnyClassIn( PostgreSQLIntervalSecondJdbcType.class ); .isOfAnyClassIn( PostgreSQLIntervalSecondJdbcType.class );
// a field that is using a @JdbcTypeCode annotation to override the JdbcType. Hence, the used JdbcType must match the one // a field that is using a @JdbcTypeCode annotation to override the JdbcType. Hence, the used JdbcType must match the one
// set by the annotation. // set by the annotation.
assertThat( entityDescriptor.findAttributeMapping( "durationJdbcTypeCode" ) assertThat( entityDescriptor.findAttributeMapping( "durationJdbcTypeCode" )
.getSingleJdbcMapping().getJdbcType() ) .getSingleJdbcMapping().getJdbcType() )
.isNotEqualTo( intervalType ) .isEqualTo( intervalType );
.isOfAnyClassIn( PostgreSQLIntervalSecondJdbcType.class );
} }
@Entity(name = "EntityWithIntervalSecondDuration") @Entity(name = "EntityWithIntervalSecondDuration")