title: JPA Criteria subquery collate: Invalid query key in expression
body: <p>I am using ecliselink, and try to convert a native SQL to Criteria API which contains subquery, but got exception that is related to collation of subquery.</p>
  
  <p>Calculate sales order total from item prices using subquery:</p>
  
  <pre><code>public class SalesOrder {
     BigDecimal totalPrice;
     public List&lt;OrderItem&gt; orderItems;
  
  }
  
  public class OrderItem {
  
     SalesOrder salesOrder;
     BigDecimal itemPrice;
  }
  
  update SalesOrder so set so.total=(select sum(itemPrice) from OrderItem oi where oi.salesOrderId=so.id);
  </code></pre>
  
  <p>Convert the update query using Criteria API</p>
  
  <pre><code>CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
  CriteriaUpdate&lt;SalesOrder&gt; criteriaUpdate = criteriaBuilder.createCriteriaUpdate(SalesOrder.class);
  
  Root&lt;SalesOrder&gt; root = criteriaUpdate.from(SalesOrder.class);
  
  Subquery&lt;BigDecimal&gt; subquery = criteriaUpdate.subquery(BigDecimal.class);
  Root&lt;InventoryForm&gt; subqueryRoot = subquery.correlate(root);
  Expression&lt;BigDecimal&gt; itemPricePath = subqueryRoot.join("orderItems", JoinType.LEFT).get("itemPrice");
  subquery.select(criteriaBuilder.sum(itemPricePath));
  
  Path&lt;BigDecimal&gt; totalPricePath = root.get("totalPrice");
  criteriaUpdate.set(totalCostPath, subquery);
  
  em.createQuery(criteriaUpdate).executeUpdate(); 
  </code></pre>
  
  <p>Got the error:</p>
  
  <pre><code>org.eclipse.persistence.exceptions.QueryException
  Exception Description: Invalid query key [orderItems] in expression.
  Query: UpdateAllQuery(referenceClass=SalesOrder )
      at org.eclipse.persistence.exceptions.QueryException.invalidQueryKeyInExpression(QueryException.java:696)
      at org.eclipse.persistence.internal.expressions.QueryKeyExpression.validateNode(QueryKeyExpression.java:1009)
      at org.eclipse.persistence.expressions.Expression.normalize(Expression.java:3275)
      at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:369)
      at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:756)
      at org.eclipse.persistence.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:669)
      at org.eclipse.persistence.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:1461)
      at org.eclipse.persistence.internal.expressions.SubSelectExpression.normalizeSubSelect(SubSelectExpression.java:205)
  </code></pre>