diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java index cb84c5f7480d..252335358337 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotEqualOperator.java @@ -28,6 +28,7 @@ package org.hisp.dhis.query.operators; import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Root; import org.hibernate.criterion.Criterion; @@ -61,7 +62,13 @@ public Predicate getPredicate(CriteriaBuilder builder, Root root, QueryPa throw new QueryException( "Left-side is collection, and right-side is not a valid integer, so can't compare by size."); } - + if (queryPath.haveAlias()) { + for (Join join : root.getJoins()) { + if (join.getAlias().equals(queryPath.getAlias()[0])) { + return builder.equal(join.get(queryPath.getProperty().getFieldName()), args.get(0)); + } + } + } return builder.notEqual(builder.size(root.get(queryPath.getPath())), value); } return builder.notEqual(root.get(queryPath.getPath()), args.get(0)); diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotInOperator.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotInOperator.java index 38eb9c1022bb..7af146be9691 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotInOperator.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/query/operators/NotInOperator.java @@ -28,6 +28,7 @@ package org.hisp.dhis.query.operators; import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.Join; import jakarta.persistence.criteria.Predicate; import jakarta.persistence.criteria.Root; import java.util.Collection; @@ -62,7 +63,13 @@ public Predicate getPredicate(CriteriaBuilder builder, Root root, QueryPa queryPath.getProperty().getItemKlass(), getCollectionArgs().get(0)))); } - + if (queryPath.haveAlias()) { + for (Join join : root.getJoins()) { + if (join.getAlias().equals(queryPath.getAlias()[0])) { + return builder.not(join.get(queryPath.getProperty().getFieldName()).in(getCollectionArgs().get(0))); + } + } + } return builder.not(root.get(queryPath.getPath()).in(getCollectionArgs().get(0))); }