Search in sources :

Example 21 with SqmPath

use of org.hibernate.query.sqm.tree.domain.SqmPath in project hibernate-orm by hibernate.

the class SelectClauseTests method testBinaryArithmeticExpressionWithMultipleFromSpaces.

@Test
public void testBinaryArithmeticExpressionWithMultipleFromSpaces() {
    final String query = "select p.numberOfToes + p2.numberOfToes as b from Person p, Person p2";
    final SqmSelectStatement<?> selectStatement = interpretSelect(query);
    final SqmQuerySpec<?> querySpec = selectStatement.getQuerySpec();
    final SqmSelection<?> selection = querySpec.getSelectClause().getSelections().get(0);
    assertThat(querySpec.getFromClause().getRoots().size(), is(2));
    final SqmRoot<?> entityRoot = querySpec.getFromClause().getRoots().get(0);
    assertThat(entityRoot.getEntityName(), endsWith("Person"));
    final SqmRoot<?> entity2Root = querySpec.getFromClause().getRoots().get(1);
    assertThat(entity2Root.getEntityName(), endsWith("Person"));
    SqmBinaryArithmetic addExpression = (SqmBinaryArithmetic) selection.getSelectableNode();
    SqmPath<?> leftHandOperand = (SqmPath<?>) addExpression.getLeftHandOperand();
    assertThat(leftHandOperand.getLhs(), sameInstance(entityRoot));
    assertThat(leftHandOperand.getReferencedPathSource().getPathName(), is("numberOfToes"));
    SqmPath<?> rightHandOperand = (SqmPath<?>) addExpression.getRightHandOperand();
    assertThat(rightHandOperand.getLhs(), sameInstance(entity2Root));
    assertThat(rightHandOperand.getReferencedPathSource().getPathName(), is("numberOfToes"));
}
Also used : SqmBinaryArithmetic(org.hibernate.query.sqm.tree.expression.SqmBinaryArithmetic) SqmPath(org.hibernate.query.sqm.tree.domain.SqmPath) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

SqmPath (org.hibernate.query.sqm.tree.domain.SqmPath)21 DiscriminatorSqmPath (org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath)10 SelfInterpretingSqmPath (org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath)10 SqmComparisonPredicate (org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate)6 HashSet (java.util.HashSet)5 Set (java.util.Set)5 SqmPredicate (org.hibernate.query.sqm.tree.predicate.SqmPredicate)5 SqmSelection (org.hibernate.query.sqm.tree.select.SqmSelection)5 AbstractMap (java.util.AbstractMap)4 HashMap (java.util.HashMap)4 IdentityHashMap (java.util.IdentityHashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 SqmLiteral (org.hibernate.query.sqm.tree.expression.SqmLiteral)4 SqmAndPredicate (org.hibernate.query.sqm.tree.predicate.SqmAndPredicate)4 SqmBetweenPredicate (org.hibernate.query.sqm.tree.predicate.SqmBetweenPredicate)4 SqmBooleanExpressionPredicate (org.hibernate.query.sqm.tree.predicate.SqmBooleanExpressionPredicate)4 SqmEmptinessPredicate (org.hibernate.query.sqm.tree.predicate.SqmEmptinessPredicate)4 SqmExistsPredicate (org.hibernate.query.sqm.tree.predicate.SqmExistsPredicate)4 SqmGroupedPredicate (org.hibernate.query.sqm.tree.predicate.SqmGroupedPredicate)4