Skip to content

Commit e6f74b5

Browse files
committed
springboot3.5.6
Signed-off-by: Abdelsalem <[email protected]>
1 parent 8c3855f commit e6f74b5

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<properties>
4545

4646
<jib.from.image>powsybl/java-dynawo:3.0.0</jib.from.image>
47-
<gridsuite-dependencies.version>44.0.0</gridsuite-dependencies.version>
47+
<gridsuite-dependencies.version>44.1.0-SNAPSHOT</gridsuite-dependencies.version>
4848
<liquibase-hibernate-package>org.gridsuite.securityanalysis.server</liquibase-hibernate-package>
4949
<db-util.version>1.0.5</db-util.version>
5050
<mockwebserver3.version>5.0.0-alpha.14</mockwebserver3.version>

src/main/java/org/gridsuite/securityanalysis/server/repositories/specifications/PreContingencyLimitViolationSpecificationBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public Specification<PreContingencyLimitViolationEntity> resultUuidEquals(UUID v
2525
}
2626

2727
public Specification<PreContingencyLimitViolationEntity> buildSpecification(UUID resultUuid, List<ResourceFilterDTO> resourceFilters) {
28-
Specification<PreContingencyLimitViolationEntity> specification = Specification.where(resultUuidEquals(resultUuid));
28+
Specification<PreContingencyLimitViolationEntity> specification = resultUuidEquals(resultUuid);
2929

3030
return SpecificationUtils.appendFiltersToSpecification(specification, resourceFilters);
3131
}

src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisResultService.java

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,30 @@ public Page<ContingencyEntity> findContingenciesPage(UUID resultUuid, UUID netwo
319319
// HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
320320
// cf. https://vladmihalcea.com/fix-hibernate-hhh000104-entity-fetch-pagination-warning-message/
321321
// We must separate in two requests, one with pagination the other one with Join Fetch
322+
// Determine which properties to project based on sort fields
323+
// When using DISTINCT, all ORDER BY columns must be in the SELECT list
324+
List<String> projectionProperties = new ArrayList<>();
325+
projectionProperties.add("uuid");
326+
327+
// Add sort properties to projection to satisfy DISTINCT + ORDER BY requirement
328+
for (Sort.Order order : modifiedPageable.getSort()) {
329+
String property = order.getProperty();
330+
if (!property.equals("uuid") && !projectionProperties.contains(property)) {
331+
projectionProperties.add(property);
332+
}
333+
}
322334

323335
// First, we fetch contingencies UUIDs, with all the filters and pagination
324-
Page<ContingencyRepository.EntityUuid> uuidPage = contingencyRepository.findBy(specification, q ->
325-
q.project("uuid")
326-
.as(ContingencyRepository.EntityUuid.class)
327-
.sortBy(modifiedPageable.getSort())
328-
.page(modifiedPageable)
329-
);
336+
Page<ContingencyRepository.EntityUuid> uuidPage = contingencyRepository.findBy(specification, q -> {
337+
var query = q.as(ContingencyRepository.EntityUuid.class)
338+
.sortBy(modifiedPageable.getSort());
339+
if (projectionProperties.size() == 1) {
340+
query = query.project("uuid");
341+
} else {
342+
query = query.project(projectionProperties.toArray(new String[0]));
343+
}
344+
return query.page(modifiedPageable);
345+
});
330346

331347
if (!uuidPage.hasContent()) {
332348
// Since springboot 3.2, the return value of Page.empty() is not serializable. See https://github.com/spring-projects/spring-data-commons/issues/2987
@@ -363,12 +379,30 @@ public Page<SubjectLimitViolationEntity> findSubjectLimitViolationsPage(UUID res
363379
// HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
364380
// cf. https://vladmihalcea.com/fix-hibernate-hhh000104-entity-fetch-pagination-warning-message/
365381
// We must separate in two requests, one with pagination the other one with Join Fetch
366-
Page<SubjectLimitViolationRepository.EntityId> uuidPage = subjectLimitViolationRepository.findBy(specification, q ->
367-
q.project("id")
368-
.as(SubjectLimitViolationRepository.EntityId.class)
369-
.sortBy(modifiedPageable.getSort())
370-
.page(modifiedPageable)
371-
);
382+
383+
// Determine which properties to project based on sort fields
384+
// When using DISTINCT, all ORDER BY columns must be in the SELECT list
385+
List<String> projectionProperties = new ArrayList<>();
386+
projectionProperties.add("id");
387+
388+
// Add sort properties to projection to satisfy DISTINCT + ORDER BY requirement
389+
for (Sort.Order order : modifiedPageable.getSort()) {
390+
String property = order.getProperty();
391+
if (!property.equals("id") && !projectionProperties.contains(property)) {
392+
projectionProperties.add(property);
393+
}
394+
}
395+
396+
Page<SubjectLimitViolationRepository.EntityId> uuidPage = subjectLimitViolationRepository.findBy(specification, q -> {
397+
var query = q.as(SubjectLimitViolationRepository.EntityId.class)
398+
.sortBy(modifiedPageable.getSort());
399+
if (projectionProperties.size() == 1) {
400+
query = query.project("id");
401+
} else {
402+
query = query.project(projectionProperties.toArray(new String[0]));
403+
}
404+
return query.page(modifiedPageable);
405+
});
372406

373407
if (!uuidPage.hasContent()) {
374408
// Since springboot 3.2, the return value of Page.empty() is not serializable. See https://github.com/spring-projects/spring-data-commons/issues/2987

0 commit comments

Comments
 (0)