From 715a12ba7eaf8fe56e6bc591d5e9fa0655a3d16a Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Wed, 22 Mar 2023 16:46:46 +0100 Subject: [PATCH] HHH-16305 Skip checking JavaObjectType function arguments --- .../function/ArgumentTypesValidator.java | 23 +++++-------------- .../NamedParameterInSelectAndWhereTest.java | 5 ++++ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java index d59944efe6..d89f630238 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/ArgumentTypesValidator.java @@ -6,6 +6,10 @@ */ package org.hibernate.query.sqm.produce.function; +import java.lang.reflect.Type; +import java.sql.Types; +import java.util.List; + import org.hibernate.QueryException; import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.mapping.JdbcMapping; @@ -16,19 +20,14 @@ import org.hibernate.query.sqm.tree.expression.SqmCollation; import org.hibernate.query.sqm.tree.expression.SqmDurationUnit; import org.hibernate.query.sqm.tree.expression.SqmExtractUnit; import org.hibernate.query.sqm.tree.expression.SqmTrimSpecification; -import org.hibernate.sql.ast.spi.AbstractSqlAstWalker; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.expression.Expression; -import org.hibernate.sql.ast.tree.expression.JdbcParameter; +import org.hibernate.type.JavaObjectType; import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.spi.JdbcTypeRecommendationException; import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators; import org.hibernate.type.spi.TypeConfiguration; -import java.lang.reflect.Type; -import java.sql.Types; -import java.util.List; - import static org.hibernate.type.SqlTypes.BIT; import static org.hibernate.type.SqlTypes.BOOLEAN; import static org.hibernate.type.SqlTypes.SMALLINT; @@ -159,9 +158,7 @@ public class ArgumentTypesValidator implements ArgumentsValidator { if (argument instanceof Expression) { JdbcMappingContainer expressionType = ((Expression) argument).getExpressionType(); if (expressionType != null) { - ParameterDetector detector = new ParameterDetector(); - argument.accept(detector); - if (detector.detected) { + if (expressionType instanceof JavaObjectType) { count += expressionType.getJdbcTypeCount(); } else { @@ -258,14 +255,6 @@ public class ArgumentTypesValidator implements ArgumentsValidator { ); } - private static class ParameterDetector extends AbstractSqlAstWalker { - private boolean detected; - @Override - public void visitParameter(JdbcParameter jdbcParameter) { - detected = true; - } - } - @Override public String getSignature() { String sig = delegate.getSignature(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/NamedParameterInSelectAndWhereTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/NamedParameterInSelectAndWhereTest.java index a8d29f743d..277291f365 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/NamedParameterInSelectAndWhereTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/NamedParameterInSelectAndWhereTest.java @@ -8,11 +8,14 @@ package org.hibernate.orm.test.query; import java.time.LocalDate; +import org.hibernate.dialect.PostgreSQLDialect; + import org.hibernate.testing.orm.domain.gambit.EntityOfBasics; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.Jira; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.testing.orm.junit.SkipForDialect; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -31,6 +34,7 @@ public class NamedParameterInSelectAndWhereTest { final EntityOfBasics e1 = new EntityOfBasics( 1 ); final EntityOfBasics e2 = new EntityOfBasics( 2 ); e2.setTheLocalDate( LocalDate.EPOCH ); + e2.setTheInt( 1 ); session.persist( e1 ); session.persist( e2 ); } ); @@ -64,6 +68,7 @@ public class NamedParameterInSelectAndWhereTest { @Test @Jira( "https://hibernate.atlassian.net/browse/HHH-16305" ) + @SkipForDialect( dialectClass = PostgreSQLDialect.class, reason = "PostgreSQL doesn't support parameters as arguments for timestampdiff" ) public void testSelectFunctionAndWhere(SessionFactoryScope scope) { scope.inTransaction( session -> assertEquals( 0, session.createQuery( "select timestampdiff(year, e.theLocalDate, :date) from EntityOfBasics e where e.theLocalDate <= :date",