diff --git a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/BinaryLogicOperatorNode.java b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/BinaryLogicOperatorNode.java index 88ce4b46cf..49fbdde66d 100644 --- a/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/BinaryLogicOperatorNode.java +++ b/hibernate-core/src/main/java/org/hibernate/hql/internal/ast/tree/BinaryLogicOperatorNode.java @@ -111,20 +111,21 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements // mutation depends on the types of nodes involved... int comparisonType = getType(); String comparisonText = getText(); + if ( !isInsideSetClause() ) { + switch ( comparisonType ) { + case HqlSqlTokenTypes.EQ: + setType( HqlSqlTokenTypes.AND ); + setText( "AND" ); + break; - switch ( comparisonType ) { - case HqlSqlTokenTypes.EQ: - setType( HqlSqlTokenTypes.AND ); - setText( "AND" ); - break; + case HqlSqlTokenTypes.NE: + setType( HqlSqlTokenTypes.OR ); + setText( "OR" ); + break; - case HqlSqlTokenTypes.NE: - setType( HqlSqlTokenTypes.OR ); - setText( "OR" ); - break; - - default: - throw new QuerySyntaxException( comparisonText + " operator not supported on composite types." ); + default: + throw new QuerySyntaxException( comparisonText + " operator not supported on composite types." ); + } } String[] lhsElementTexts = extractMutationTexts( getLeftHandOperand(), valueElements ); @@ -153,8 +154,10 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements } protected void translate( - int valueElements, int comparisonType, - String comparisonText, String[] lhsElementTexts, + int valueElements, + int comparisonType, + String comparisonText, + String[] lhsElementTexts, String[] rhsElementTexts, ParameterSpecification lhsEmbeddedCompositeParameterSpecification, ParameterSpecification rhsEmbeddedCompositeParameterSpecification, @@ -164,14 +167,21 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements for ( int i = valueElements - 1; i > 0; i-- ) { if ( i == 1 ) { - AST op1 = getASTFactory().create( comparisonType, comparisonText ); + final AST op1; + if ( isInsideSetClause() ) { + op1 = container; + } + else { + op1 = getASTFactory().create( comparisonType, comparisonText ); + } + SqlFragment lhs1 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, lhsElementTexts[0] ); SqlFragment rhs1 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, rhsElementTexts[0] ); copyReferencedTables( leftHandOperand, lhs1 ); copyReferencedTables( rightHandOperand, rhs1 ); op1.setFirstChild( lhs1 ); lhs1.setNextSibling( rhs1 ); - container.setFirstChild( op1 ); + AST op2 = getASTFactory().create( comparisonType, comparisonText ); SqlFragment lhs2 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, lhsElementTexts[1] ); SqlFragment rhs2 = (SqlFragment) getASTFactory().create( HqlSqlTokenTypes.SQL_TOKEN, rhsElementTexts[1] ); @@ -181,6 +191,10 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements lhs2.setNextSibling( rhs2 ); op1.setNextSibling( op2 ); + if ( !isInsideSetClause() ) { + container.setFirstChild( op1 ); + } + // "pass along" our initial embedded parameter node(s) to the first generated // sql fragment so that it can be handled later for parameter binding... if ( lhsEmbeddedCompositeParameterSpecification != null ) { @@ -206,6 +220,10 @@ public class BinaryLogicOperatorNode extends AbstractSelectExpression implements } } + private boolean isInsideSetClause() { + return getWalker().getCurrentClauseType() == HqlSqlTokenTypes.SET; + } + private static void copyReferencedTables(Node from, SqlFragment to) { if (from instanceof TableReferenceNode) { TableReferenceNode tableReferenceNode = (TableReferenceNode) from;