HHH-16305 Skip checking JavaObjectType function arguments

This commit is contained in:
Marco Belladelli 2023-03-22 16:46:46 +01:00
parent 3942961eeb
commit 715a12ba7e
2 changed files with 11 additions and 17 deletions

View File

@ -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();

View File

@ -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",