expression.getEntityExpression().accept(this);
Expression entityExpression = queryExpression;
if (expression.hasNot()) {
CollectionValuedPathExpression pathExpression = (CollectionValuedPathExpression) expression.getCollectionValuedPathExpression();
// Retrieve the ExpressionBuilder from the collection-valued path expression's
// identification variable and the variable name
pathExpression.getIdentificationVariable().accept(this);
Expression parentExpression = queryExpression;
// Now create the actual expression
Expression newBuilder = new ExpressionBuilder();
Expression collectionBase = newBuilder;
for (int i = 1; i < pathExpression.pathSize() - 1; i++) {
// nested paths must be single valued.
collectionBase = collectionBase.get(pathExpression.getPath(i));
}
String lastPath = pathExpression.getPath(pathExpression.pathSize() - 1);
// The following code is copied from Expression.noneOf and altered a bit
Expression criteria = newBuilder.equal(parentExpression).and(collectionBase.anyOf(lastPath).equal(entityExpression));
ReportQuery subQuery = new ReportQuery();
subQuery.setShouldRetrieveFirstPrimaryKey(true);
subQuery.setSelectionCriteria(criteria);