Fix HANA test issues

This commit is contained in:
Christian Beikov 2023-02-02 18:04:21 +01:00
parent f6f2db18da
commit f11a18dae0
3 changed files with 21 additions and 1 deletions

View File

@ -1164,6 +1164,12 @@ public abstract class AbstractHANADialect extends Dialect {
public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) { public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) {
switch (unit) { switch (unit) {
case NANOSECOND: 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: case NATIVE:
if ( temporalType == TemporalType.TIME ) { if ( temporalType == TemporalType.TIME ) {
return "cast(add_nano100('1970-01-01 '||(?3),?2) as 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) { public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalType, TemporalType toTemporalType) {
switch (unit) { switch (unit) {
case NANOSECOND: 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: case NATIVE:
// if ( temporalType == TemporalType.TIME ) { // if ( temporalType == TemporalType.TIME ) {
// return "nano100_between(cast(?3 as timestamp), cast(?2 as timestamp))"; // return "nano100_between(cast(?3 as timestamp), cast(?2 as timestamp))";

View File

@ -20,6 +20,8 @@ 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.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.FailureExpected;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -40,6 +42,7 @@ public class FieldAccessedNestedEmbeddableMetadataTest {
final Metadata metadata = new MetadataSources( ssr ) final Metadata metadata = new MetadataSources( ssr )
.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" );
@ -54,7 +57,10 @@ public class FieldAccessedNestedEmbeddableMetadataTest {
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.getJdbcTypeRegistry().getDescriptor( Types.VARCHAR ).getJdbcTypeCode(),
currencySqlTypes[0]
);
} }
finally { finally {
StandardServiceRegistryBuilder.destroy( ssr ); StandardServiceRegistryBuilder.destroy( ssr );

View File

@ -13,6 +13,7 @@ import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.hibernate.annotations.JdbcTypeCode; import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.dialect.OracleDialect; import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.SybaseDialect; import org.hibernate.dialect.SybaseDialect;
import org.hibernate.type.SqlTypes; import org.hibernate.type.SqlTypes;
@ -214,6 +215,7 @@ public class VarbinaryArrayTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("perTypeArguments") @MethodSource("perTypeArguments")
@SkipForDialect( dialectClass = AbstractHANADialect.class, matchSubTypes = true, reason = "For some reason, HANA can't intersect VARBINARY values, but funnily can do a union...")
<T> void queryByData(String propertyName, long id, T value, Function<EntityWithArrays, T> getter, <T> void queryByData(String propertyName, long id, T value, Function<EntityWithArrays, T> getter,
SessionFactoryScope scope) { SessionFactoryScope scope) {
scope.inTransaction( session -> { scope.inTransaction( session -> {