From 29bfb799aab84d796110753416093574cfcc967b Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Tue, 21 Dec 2021 18:26:37 +0100 Subject: [PATCH] Fix some test issues with HANA and emulate derived table column naming on HANA --- .../mapping/basic/CharacterArrayMappingTests.java | 10 ++++++---- .../mapping/basic/CharacterMappingTests.java | 6 ++++-- .../userguide/mapping/basic/ClassMappingTests.java | 4 +++- .../mapping/basic/CurrencyMappingTests.java | 4 +++- .../userguide/mapping/basic/LocaleMappingTests.java | 4 +++- .../userguide/mapping/basic/StringMappingTests.java | 6 ++++-- .../mapping/basic/TimeZoneMappingTests.java | 4 +++- .../mapping/basic/ZoneOffsetMappingTests.java | 4 +++- .../org/hibernate/dialect/HANASqlAstTranslator.java | 13 +++++++++++++ 9 files changed, 42 insertions(+), 13 deletions(-) diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CharacterArrayMappingTests.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CharacterArrayMappingTests.java index 50388164de..35b1ce3fff 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CharacterArrayMappingTests.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CharacterArrayMappingTests.java @@ -17,6 +17,7 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; 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.SessionFactory; @@ -35,31 +36,32 @@ public class CharacterArrayMappingTests { @Test public void verifyMappings(SessionFactoryScope scope) { final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final JdbcTypeRegistry jdbcRegistry = domainModel.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( EntityWithCharArrays.class ); { final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "primitive" ); final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping(); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.VARCHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.VARCHAR ) ) ); } { final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "wrapper" ); final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping(); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.VARCHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.VARCHAR ) ) ); } { final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "primitiveClob" ); final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping(); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.CLOB ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.CLOB ) ) ); } { final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "wrapperClob" ); final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping(); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.CLOB ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.CLOB ) ) ); } } diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CharacterMappingTests.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CharacterMappingTests.java index c588baf087..f0e45db364 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CharacterMappingTests.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CharacterMappingTests.java @@ -15,6 +15,7 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; 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.SessionFactory; @@ -41,6 +42,7 @@ public class CharacterMappingTests { public void testMappings(SessionFactoryScope scope) { // first, verify the type selections... final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final JdbcTypeRegistry jdbcRegistry = domainModel.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( EntityOfCharacters.class ); { @@ -49,7 +51,7 @@ public class CharacterMappingTests { final JdbcMapping jdbcMapping = attribute.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( Character.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.CHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.CHAR ) ) ); } { @@ -58,7 +60,7 @@ public class CharacterMappingTests { final JdbcMapping jdbcMapping = attribute.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( Character.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.CHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.CHAR ) ) ); } diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/ClassMappingTests.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/ClassMappingTests.java index 3493dd344a..103564235f 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/ClassMappingTests.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/ClassMappingTests.java @@ -16,6 +16,7 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; 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.SessionFactory; @@ -35,12 +36,13 @@ public class ClassMappingTests { @Test public void verifyMappings(SessionFactoryScope scope) { final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final JdbcTypeRegistry jdbcRegistry = domainModel.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( EntityWithClass.class ); final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "clazz" ); final JdbcMapping jdbcMapping = duration.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( Class.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.VARCHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.VARCHAR ) ) ); scope.inTransaction( (session) -> { diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CurrencyMappingTests.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CurrencyMappingTests.java index 8963e4b533..83fd075dc5 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CurrencyMappingTests.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/CurrencyMappingTests.java @@ -16,6 +16,7 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; 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.SessionFactory; @@ -35,12 +36,13 @@ public class CurrencyMappingTests { @Test public void verifyMappings(SessionFactoryScope scope) { final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final JdbcTypeRegistry jdbcRegistry = domainModel.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( EntityWithCurrency.class ); final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "currency" ); final JdbcMapping jdbcMapping = duration.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( Currency.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.VARCHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.VARCHAR ) ) ); scope.inTransaction( (session) -> { diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/LocaleMappingTests.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/LocaleMappingTests.java index 7d0657f495..bb20158181 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/LocaleMappingTests.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/LocaleMappingTests.java @@ -17,6 +17,7 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; 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.SessionFactory; @@ -36,12 +37,13 @@ public class LocaleMappingTests { @Test public void verifyMappings(SessionFactoryScope scope) { final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final JdbcTypeRegistry jdbcRegistry = domainModel.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( EntityWithLocale.class ); final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "locale" ); final JdbcMapping jdbcMapping = duration.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( Locale.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.VARCHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.VARCHAR ) ) ); scope.inTransaction( (session) -> { diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/StringMappingTests.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/StringMappingTests.java index 3bae678f94..cdacb7a548 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/StringMappingTests.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/StringMappingTests.java @@ -16,6 +16,7 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; 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.SessionFactory; @@ -39,6 +40,7 @@ public class StringMappingTests { public void testMappings(SessionFactoryScope scope) { // first, verify the type selections... final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final JdbcTypeRegistry jdbcRegistry = domainModel.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( EntityOfStrings.class ); { @@ -47,14 +49,14 @@ public class StringMappingTests { final JdbcMapping jdbcMapping = attribute.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( String.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.VARCHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.VARCHAR ) ) ); } { final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "clobString" ); final JdbcMapping jdbcMapping = attribute.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( String.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.CLOB ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.CLOB ) ) ); } diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/TimeZoneMappingTests.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/TimeZoneMappingTests.java index 788dcccfb3..c3bcbb934a 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/TimeZoneMappingTests.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/TimeZoneMappingTests.java @@ -18,6 +18,7 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; 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.SessionFactory; @@ -37,12 +38,13 @@ public class TimeZoneMappingTests { @Test public void verifyMappings(SessionFactoryScope scope) { final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final JdbcTypeRegistry jdbcRegistry = domainModel.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( EntityWithTimeZone.class ); final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "timeZone" ); final JdbcMapping jdbcMapping = duration.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( TimeZone.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.VARCHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.VARCHAR ) ) ); scope.inTransaction( (session) -> { diff --git a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/ZoneOffsetMappingTests.java b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/ZoneOffsetMappingTests.java index 7aea3e2c66..b14c46b410 100644 --- a/documentation/src/test/java/org/hibernate/userguide/mapping/basic/ZoneOffsetMappingTests.java +++ b/documentation/src/test/java/org/hibernate/userguide/mapping/basic/ZoneOffsetMappingTests.java @@ -17,6 +17,7 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping; 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.SessionFactory; @@ -36,12 +37,13 @@ public class ZoneOffsetMappingTests { @Test public void verifyMappings(SessionFactoryScope scope) { final MappingMetamodel domainModel = scope.getSessionFactory().getDomainModel(); + final JdbcTypeRegistry jdbcRegistry = domainModel.getTypeConfiguration().getJdbcTypeDescriptorRegistry(); final EntityPersister entityDescriptor = domainModel.findEntityDescriptor( EntityWithZoneOffset.class ); final BasicAttributeMapping duration = (BasicAttributeMapping) entityDescriptor.findAttributeMapping( "zoneOffset" ); final JdbcMapping jdbcMapping = duration.getJdbcMapping(); assertThat( jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo( ZoneOffset.class ) ); - assertThat( jdbcMapping.getJdbcTypeDescriptor().getJdbcTypeCode(), equalTo( Types.VARCHAR ) ); + assertThat( jdbcMapping.getJdbcTypeDescriptor(), equalTo( jdbcRegistry.getDescriptor( Types.VARCHAR ) ) ); scope.inTransaction( (session) -> { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/HANASqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/HANASqlAstTranslator.java index eddb145d78..6a98b98928 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/HANASqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/HANASqlAstTranslator.java @@ -14,6 +14,8 @@ import org.hibernate.sql.ast.tree.cte.CteStatement; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.Literal; import org.hibernate.sql.ast.tree.expression.Summarization; +import org.hibernate.sql.ast.tree.from.FunctionTableReference; +import org.hibernate.sql.ast.tree.from.QueryPartTableReference; import org.hibernate.sql.ast.tree.select.QueryGroup; import org.hibernate.sql.ast.tree.select.QueryPart; import org.hibernate.sql.ast.tree.select.QuerySpec; @@ -57,6 +59,17 @@ public class HANASqlAstTranslator extends AbstractSqlAs } } + @Override + public void visitQueryPartTableReference(QueryPartTableReference tableReference) { + emulateQueryPartTableReferenceColumnAliasing( tableReference ); + } + + @Override + public void visitFunctionTableReference(FunctionTableReference tableReference) { + tableReference.getFunctionExpression().accept( this ); + renderTableReferenceIdentificationVariable( tableReference ); + } + @Override public void visitOffsetFetchClause(QueryPart queryPart) { if ( !isRowNumberingCurrentQueryPart() ) {