From 3b19a4353fa9061795bfe833a0693d098a645561 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Tue, 29 Oct 2024 11:14:51 +0100 Subject: [PATCH] HHH-18709 Also apply inferrable types to jpa criteria parameters --- .../query/sqm/internal/QuerySqmImpl.java | 6 ++-- .../tree/expression/AbstractSqmParameter.java | 2 +- .../tree/expression/JpaCriteriaParameter.java | 28 ++++--------------- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java index 2c998992c219..4eed34fe3eb4 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/QuerySqmImpl.java @@ -74,6 +74,7 @@ import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter; import org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper; import org.hibernate.query.sqm.tree.expression.SqmParameter; +import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter; import org.hibernate.query.sqm.tree.from.SqmRoot; import org.hibernate.query.sqm.tree.insert.SqmInsertStatement; import org.hibernate.query.sqm.tree.insert.SqmInsertValuesStatement; @@ -245,9 +246,8 @@ public QuerySqmImpl( private void bindCriteriaParameter(SqmJpaCriteriaParameterWrapper sqmParameter) { final JpaCriteriaParameter jpaCriteriaParameter = sqmParameter.getJpaCriteriaParameter(); final T value = jpaCriteriaParameter.getValue(); - // We don't set a null value, unless the type is also null which - // is the case when using HibernateCriteriaBuilder.value - if ( value != null || jpaCriteriaParameter.getNodeType() == null ) { + // We don't set a null value, unless using HibernateCriteriaBuilder.value + if ( value != null || jpaCriteriaParameter instanceof ValueBindJpaCriteriaParameter ) { // Use the anticipated type for binding the value if possible getQueryParameterBindings().getBinding( jpaCriteriaParameter ) .setBindValue( value, jpaCriteriaParameter.getAnticipatedType() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmParameter.java index 33a35f8b0d7a..927aef974291 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmParameter.java @@ -21,7 +21,7 @@ public abstract class AbstractSqmParameter extends AbstractSqmExpression i public AbstractSqmParameter( boolean canBeMultiValued, - SqmExpressible inherentType, + SqmExpressible inherentType, NodeBuilder nodeBuilder) { super( inherentType, nodeBuilder ); this.canBeMultiValued = canBeMultiValued; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/JpaCriteriaParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/JpaCriteriaParameter.java index 89ee5cf734aa..cf512f68a144 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/JpaCriteriaParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/JpaCriteriaParameter.java @@ -27,25 +27,22 @@ * @author Steve Ebersole */ public class JpaCriteriaParameter - extends AbstractSqmExpression - implements SqmParameter, QueryParameterImplementor { + extends AbstractSqmParameter + implements QueryParameterImplementor { private final String name; - private boolean allowsMultiValuedBinding; public JpaCriteriaParameter( String name, BindableType type, boolean allowsMultiValuedBinding, NodeBuilder nodeBuilder) { - super( toSqmType( type, nodeBuilder ), nodeBuilder ); + super( allowsMultiValuedBinding, toSqmType( type, nodeBuilder ), nodeBuilder ); this.name = name; - this.allowsMultiValuedBinding = allowsMultiValuedBinding; } protected JpaCriteriaParameter(JpaCriteriaParameter original) { - super( original.getNodeType(), original.nodeBuilder() ); + super( original.allowMultiValuedBinding(), original.getNodeType(), original.nodeBuilder() ); this.name = original.name; - this.allowsMultiValuedBinding = original.allowsMultiValuedBinding; } private static SqmExpressible toSqmType(BindableType type, NodeBuilder nodeBuilder) { @@ -84,17 +81,7 @@ public Integer getTupleLength() { @Override public boolean allowsMultiValuedBinding() { - return allowsMultiValuedBinding; - } - - @Override - public void disallowMultiValuedBinding() { - allowsMultiValuedBinding = false; - } - - @Override - public boolean allowMultiValuedBinding() { - return allowsMultiValuedBinding(); + return allowMultiValuedBinding(); } @Override @@ -129,11 +116,6 @@ public Class getParameterType() { return nodeType == null ? null : nodeType.getExpressibleJavaType().getJavaTypeClass(); } - @Override - protected void internalApplyInferableType(SqmExpressible newType) { - super.internalApplyInferableType( newType ); - } - @Override public X accept(SemanticQueryWalker walker) { return walker.visitJpaCriteriaParameter( this );