#6199 - ensure order by clause is included in the sql string.

This commit is contained in:
ddpardo 2024-08-22 13:45:50 +02:00
parent 709756d68d
commit eb53506d1a
1 changed files with 5 additions and 0 deletions

View File

@ -115,6 +115,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.tuple.Pair; 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.IAnyResource;
import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IBaseResource;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -1584,6 +1585,10 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
String sql = localReferenceQuery + " UNION " + canonicalQuery.getLeft(); String sql = localReferenceQuery + " UNION " + canonicalQuery.getLeft();
if(myDialectProvider.getDialect() instanceof SQLServerDialect) {
sql += " order by r." + findPidFieldSqlColumn;
}
List<Collection<JpaPid>> partitions = partition(nextRoundMatches, getMaximumPageSize()); List<Collection<JpaPid>> partitions = partition(nextRoundMatches, getMaximumPageSize());
for (Collection<JpaPid> nextPartition : partitions) { for (Collection<JpaPid> nextPartition : partitions) {
Query q = entityManager.createNativeQuery(sql, Tuple.class); Query q = entityManager.createNativeQuery(sql, Tuple.class);