From 9e8fe5ca0711af6f32ae16122a739018aafc8b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Kuruc?= Date: Fri, 22 Mar 2024 22:49:57 +0100 Subject: [PATCH] HHH-14080 fix Dialect-Aware Rendering of Null Value Literals for InformixDialect --- .../community/dialect/InformixDialect.java | 7 +++++++ .../community/dialect/InformixSqlAstTranslator.java | 13 +++++++++++++ .../sql/ast/spi/AbstractSqlAstTranslator.java | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java index 888c09af46..44a68829c3 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java @@ -59,6 +59,7 @@ import org.hibernate.sql.exec.spi.JdbcOperation; import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor; import org.hibernate.type.descriptor.sql.internal.CapacityDependentDdlType; import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry; +import org.hibernate.type.spi.TypeConfiguration; import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate; import static org.hibernate.type.SqlTypes.BIGINT; @@ -594,4 +595,10 @@ public class InformixDialect extends Dialect { .replace("S", "%F1"); } + @Override + public String getSelectClauseNullString(int sqlType, TypeConfiguration typeConfiguration) { + String typeName = typeConfiguration.getDdlTypeRegistry().getDescriptor( sqlType).getRawTypeName(); + return "null::" + typeName; + } + } diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java index 63c3d9c200..8ffa01c21c 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixSqlAstTranslator.java @@ -10,6 +10,7 @@ import java.util.List; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.query.sqm.ComparisonOperator; +import org.hibernate.sql.ast.SqlAstNodeRenderingMode; import org.hibernate.sql.ast.spi.AbstractSqlAstTranslator; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.Statement; @@ -143,6 +144,18 @@ public class InformixSqlAstTranslator extends AbstractS return " from " + getDual() + " dual"; } + @Override + protected void renderNull(Literal literal) { + if ( getParameterRenderingMode() == SqlAstNodeRenderingMode.NO_UNTYPED ) { + renderCasted( literal ); + } + else { + int sqlType = literal.getExpressionType().getSingleJdbcMapping().getJdbcType().getJdbcTypeCode(); + String nullString = getDialect().getSelectClauseNullString( sqlType, getSessionFactory().getTypeConfiguration() ); + appendSql( nullString ); + } + } + private boolean supportsParameterOffsetFetchExpression() { return getDialect().getVersion().isSameOrAfter( 11 ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java index e84d6f00b0..48c318966e 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java @@ -7413,7 +7413,7 @@ public abstract class AbstractSqlAstTranslator implemen } } - private void renderNull(Literal literal) { + protected void renderNull(Literal literal) { if ( getParameterRenderingMode() == SqlAstNodeRenderingMode.NO_UNTYPED ) { renderCasted( literal ); }