From 57f5769ee56d43828626445fe8688f928235879a Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Fri, 10 Feb 2023 23:10:13 +0100 Subject: [PATCH] HHH-16170 Check for enums in update statement --- .../hql/internal/SemanticQueryBuilder.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index fccd78a97b..6617bfc858 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -573,10 +573,25 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implem if ( subCtx instanceof HqlParser.AssignmentContext ) { final HqlParser.AssignmentContext assignmentContext = (HqlParser.AssignmentContext) subCtx; //noinspection unchecked - updateStatement.applyAssignment( - (SqmPath) consumeDomainPath( (HqlParser.SimplePathContext) assignmentContext.getChild( 0 ) ), - (SqmExpression) assignmentContext.getChild( 2 ).accept( this ) - ); + final SqmPath targetPath = (SqmPath) consumeDomainPath( (HqlParser.SimplePathContext) assignmentContext.getChild( 0 ) ); + final Class targetPathJavaType = targetPath.getJavaType(); + final boolean isEnum = targetPathJavaType != null && targetPathJavaType.isEnum(); + final ParseTree rightSide = assignmentContext.getChild( 2 ); + final HqlParser.ExpressionContext expressionContext; + final Map, Enum> possibleEnumValues; + final SqmExpression value; + if ( isEnum && rightSide.getChild( 0 ) instanceof HqlParser.ExpressionContext + && ( possibleEnumValues = getPossibleEnumValues( expressionContext = (HqlParser.ExpressionContext) rightSide.getChild( 0 ) ) ) != null ) { + value = resolveEnumShorthandLiteral( + expressionContext, + possibleEnumValues, + targetPathJavaType + ); + } + else { + value = (SqmExpression) rightSide.accept( this ); + } + updateStatement.applyAssignment( targetPath, value ); } }