HHH-16170 Check for enums in update statement

This commit is contained in:
Marco Belladelli 2023-02-10 23:10:13 +01:00 committed by Christian Beikov
parent 984f7ff571
commit 57f5769ee5
1 changed files with 19 additions and 4 deletions

View File

@ -573,10 +573,25 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
if ( subCtx instanceof HqlParser.AssignmentContext ) { if ( subCtx instanceof HqlParser.AssignmentContext ) {
final HqlParser.AssignmentContext assignmentContext = (HqlParser.AssignmentContext) subCtx; final HqlParser.AssignmentContext assignmentContext = (HqlParser.AssignmentContext) subCtx;
//noinspection unchecked //noinspection unchecked
updateStatement.applyAssignment( final SqmPath<Object> targetPath = (SqmPath<Object>) consumeDomainPath( (HqlParser.SimplePathContext) assignmentContext.getChild( 0 ) );
(SqmPath<Object>) consumeDomainPath( (HqlParser.SimplePathContext) assignmentContext.getChild( 0 ) ), final Class<?> targetPathJavaType = targetPath.getJavaType();
(SqmExpression<?>) assignmentContext.getChild( 2 ).accept( this ) final boolean isEnum = targetPathJavaType != null && targetPathJavaType.isEnum();
); final ParseTree rightSide = assignmentContext.getChild( 2 );
final HqlParser.ExpressionContext expressionContext;
final Map<Class<?>, 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 );
} }
} }