diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index ded5b0309d..6761db4d44 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -1671,14 +1671,11 @@ public abstract class BaseSqmToSqlAstConverter ); } else { - return new BinaryArithmeticExpression( - toSqlExpression( leftOperand.accept(this) ), + toSqlExpression( leftOperand.accept( this ) ), expression.getOperator(), - toSqlExpression( rightOperand.accept(this) ), - expression.getNodeType() instanceof BasicValuedMapping - ? (BasicValuedMapping) expression.getNodeType() - : (BasicValuedMapping) expression.getLeftHandOperand().getNodeType() + toSqlExpression( rightOperand.accept( this ) ), + getExpressionType( expression ) ); } } @@ -1687,6 +1684,16 @@ public abstract class BaseSqmToSqlAstConverter } } + private BasicValuedMapping getExpressionType(SqmBinaryArithmetic expression) { + SqmExpressable leftHandOperandType = expression.getLeftHandOperand().getNodeType(); + if ( leftHandOperandType instanceof BasicValuedMapping ) { + return (BasicValuedMapping) leftHandOperandType; + } + else { + return (BasicValuedMapping) expression.getRightHandOperand().getNodeType(); + } + } + private Expression toSqlExpression(Object value) { return (Expression) value; }