diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java index 1b477e77b0e..de51f138575 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/QueryStack.java @@ -1476,12 +1476,12 @@ public class QueryStack { public void addGrouping() { BaseJoiningPredicateBuilder firstPredicateBuilder = mySqlBuilder.getOrCreateFirstPredicateBuilder(); - mySqlBuilder.getSelect().addGroupings(firstPredicateBuilder.getJoinColumns()); + mySqlBuilder.getSelect().addGroupings(firstPredicateBuilder.getResourceIdColumn()); } public void addOrdering() { BaseJoiningPredicateBuilder firstPredicateBuilder = mySqlBuilder.getOrCreateFirstPredicateBuilder(); - mySqlBuilder.getSelect().addOrderings(firstPredicateBuilder.getJoinColumns()); + mySqlBuilder.getSelect().addOrderings(firstPredicateBuilder.getResourceIdColumn()); } public Condition createPredicateReferenceForEmbeddedChainedSearchResource(