From ee3129d45b2de8ce54ac4ef72d086e7c574b1f08 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 13 Apr 2022 11:12:54 +0200 Subject: [PATCH] HHH-15142 CriteriaQuery with Like predicate fails when repeated with java.lang.IllegalArgumentException: Parameter value [] did not match expected type [java.lang.String (n/a)] --- .../query/criteria/internal/compile/CriteriaCompiler.java | 5 ++--- .../internal/expression/ParameterExpressionImpl.java | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/compile/CriteriaCompiler.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/compile/CriteriaCompiler.java index b41adfa637..d4c685c9d5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/compile/CriteriaCompiler.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/compile/CriteriaCompiler.java @@ -94,7 +94,7 @@ public class CriteriaCompiler implements Serializable { public ExplicitParameterInfo registerExplicitParameter(ParameterExpression criteriaQueryParameter) { ExplicitParameterInfo parameterInfo = explicitParameterInfoMap.get( criteriaQueryParameter ); if ( parameterInfo == null ) { - if ( StringHelper.isNotEmpty( criteriaQueryParameter.getName() ) ) { + if ( StringHelper.isNotEmpty( criteriaQueryParameter.getName() ) && !( (ParameterExpressionImpl) criteriaQueryParameter ).isNameGenerated() ) { parameterInfo = new ExplicitParameterInfo( criteriaQueryParameter.getName(), null, @@ -109,9 +109,8 @@ public class CriteriaCompiler implements Serializable { ); } else { - final String name = generateParameterName(); parameterInfo = new ExplicitParameterInfo( - name, + generateParameterName(), null, criteriaQueryParameter.getJavaType() ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/expression/ParameterExpressionImpl.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/expression/ParameterExpressionImpl.java index 7875341724..4c565350cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/expression/ParameterExpressionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/expression/ParameterExpressionImpl.java @@ -25,6 +25,7 @@ public class ParameterExpressionImpl implements ParameterExpression, Serializable { private String name; private final Integer position; + private boolean isNameGenerated; public ParameterExpressionImpl( CriteriaBuilderImpl criteriaBuilder, @@ -57,6 +58,10 @@ public class ParameterExpressionImpl return name; } + public boolean isNameGenerated() { + return isNameGenerated; + } + @Override public Integer getPosition() { return position; @@ -76,6 +81,7 @@ public class ParameterExpressionImpl public String render(RenderingContext renderingContext) { final ExplicitParameterInfo parameterInfo = renderingContext.registerExplicitParameter( this ); if ( name == null && position == null ) { + isNameGenerated = true; name = parameterInfo.getName(); } return parameterInfo.render();