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)]

This commit is contained in:
Andrea Boriero 2022-04-13 11:12:54 +02:00 committed by Andrea Boriero
parent f1c46277e5
commit ee3129d45b
2 changed files with 8 additions and 3 deletions

View File

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

View File

@ -25,6 +25,7 @@ public class ParameterExpressionImpl<T>
implements ParameterExpression<T>, Serializable {
private String name;
private final Integer position;
private boolean isNameGenerated;
public ParameterExpressionImpl(
CriteriaBuilderImpl criteriaBuilder,
@ -57,6 +58,10 @@ public class ParameterExpressionImpl<T>
return name;
}
public boolean isNameGenerated() {
return isNameGenerated;
}
@Override
public Integer getPosition() {
return position;
@ -76,6 +81,7 @@ public class ParameterExpressionImpl<T>
public String render(RenderingContext renderingContext) {
final ExplicitParameterInfo parameterInfo = renderingContext.registerExplicitParameter( this );
if ( name == null && position == null ) {
isNameGenerated = true;
name = parameterInfo.getName();
}
return parameterInfo.render();