From eb53506d1afb2d4563295c65e2ca340af12473e7 Mon Sep 17 00:00:00 2001 From: ddpardo <2494889+ddpardo@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:45:50 +0200 Subject: [PATCH] #6199 - ensure order by clause is included in the sql string. --- .../java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java index bb50e0dd613..193c5cee256 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java @@ -115,6 +115,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.tuple.Pair; +import org.hibernate.dialect.SQLServerDialect; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.slf4j.Logger; @@ -1584,6 +1585,10 @@ public class SearchBuilder implements ISearchBuilder { String sql = localReferenceQuery + " UNION " + canonicalQuery.getLeft(); + if(myDialectProvider.getDialect() instanceof SQLServerDialect) { + sql += " order by r." + findPidFieldSqlColumn; + } + List> partitions = partition(nextRoundMatches, getMaximumPageSize()); for (Collection nextPartition : partitions) { Query q = entityManager.createNativeQuery(sql, Tuple.class);