From 5e8b43edf90b26ccb5c8ab4af1a02e32eb2bb1ba Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Thu, 2 Feb 2023 18:04:21 +0100 Subject: [PATCH] Fix HANA test issues --- .../org/hibernate/dialect/AbstractHANADialect.java | 12 ++++++++++++ .../FieldAccessedNestedEmbeddableMetadataTest.java | 8 +++++++- .../hibernate/orm/test/type/VarbinaryArrayTest.java | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java index 5f7868b906..66636f85fa 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/AbstractHANADialect.java @@ -1164,6 +1164,12 @@ public abstract class AbstractHANADialect extends Dialect { public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) { switch (unit) { case NANOSECOND: + if ( temporalType == TemporalType.TIME ) { + return "cast(add_nano100('1970-01-01 '||(?3),?2/100) as time)"; + } + else { + return "add_nano100(?3,?2/100)"; + } case NATIVE: if ( temporalType == TemporalType.TIME ) { return "cast(add_nano100('1970-01-01 '||(?3),?2) as time)"; @@ -1188,6 +1194,12 @@ public abstract class AbstractHANADialect extends Dialect { public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalType, TemporalType toTemporalType) { switch (unit) { case NANOSECOND: +// if ( temporalType == TemporalType.TIME ) { +// return "nano100_between(cast(?3 as timestamp), cast(?2 as timestamp))*100"; +// } +// else { + return "nano100_between(?2,?3)*100"; +// } case NATIVE: // if ( temporalType == TemporalType.TIME ) { // return "nano100_between(cast(?3 as timestamp), cast(?2 as timestamp))"; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/nested/fieldaccess/FieldAccessedNestedEmbeddableMetadataTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/nested/fieldaccess/FieldAccessedNestedEmbeddableMetadataTest.java index 5acc6d1c49..e34c253a99 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/nested/fieldaccess/FieldAccessedNestedEmbeddableMetadataTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/embeddables/nested/fieldaccess/FieldAccessedNestedEmbeddableMetadataTest.java @@ -20,6 +20,8 @@ import org.hibernate.mapping.Property; import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.Value; import org.hibernate.type.CustomType; +import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; +import org.hibernate.type.spi.TypeConfiguration; import org.hibernate.testing.orm.junit.FailureExpected; import org.junit.jupiter.api.Test; @@ -40,6 +42,7 @@ public class FieldAccessedNestedEmbeddableMetadataTest { final Metadata metadata = new MetadataSources( ssr ) .addAnnotatedClass( Customer.class ) .buildMetadata(); + final TypeConfiguration typeConfiguration = metadata.getDatabase().getTypeConfiguration(); PersistentClass classMetadata = metadata.getEntityBinding( Customer.class.getName() ); Property investmentsProperty = classMetadata.getProperty( "investments" ); @@ -54,7 +57,10 @@ public class FieldAccessedNestedEmbeddableMetadataTest { CustomType currencyType = (CustomType) currencyMetadata.getType(); int[] currencySqlTypes = currencyType.getSqlTypeCodes( metadata ); assertEquals( 1, currencySqlTypes.length ); - assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] ); + assertJdbcTypeCode( + typeConfiguration.getJdbcTypeRegistry().getDescriptor( Types.VARCHAR ).getJdbcTypeCode(), + currencySqlTypes[0] + ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/type/VarbinaryArrayTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/type/VarbinaryArrayTest.java index 2bbfaec5a0..fa170c9b7a 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/type/VarbinaryArrayTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/type/VarbinaryArrayTest.java @@ -13,6 +13,7 @@ import java.util.function.Function; import java.util.stream.Stream; import org.hibernate.annotations.JdbcTypeCode; +import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.OracleDialect; import org.hibernate.dialect.SybaseDialect; import org.hibernate.type.SqlTypes; @@ -214,6 +215,7 @@ public class VarbinaryArrayTest { @ParameterizedTest @MethodSource("perTypeArguments") + @SkipForDialect( dialectClass = AbstractHANADialect.class, matchSubTypes = true, reason = "For some reason, HANA can't intersect VARBINARY values, but funnily can do a union...") void queryByData(String propertyName, long id, T value, Function getter, SessionFactoryScope scope) { scope.inTransaction( session -> {