Skip to content

Commit 014d921

Browse files
authored
springboot3.5.6 (#205)
Signed-off-by: Abdelsalem <[email protected]>
1 parent 2da7f47 commit 014d921

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
@@ -42,8 +42,8 @@
4242
</developers>
4343

4444
<properties>
45+
<gridsuite-dependencies.version>45.0.0</gridsuite-dependencies.version>
4546
<jib.from.image>powsybl/java-dynawo:3.1.0</jib.from.image>
46-
<gridsuite-dependencies.version>44.1.0</gridsuite-dependencies.version>
4747
<liquibase-hibernate-package>org.gridsuite.securityanalysis.server</liquibase-hibernate-package>
4848
<db-util.version>1.0.5</db-util.version>
4949
<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
@@ -321,14 +321,30 @@ public Page<ContingencyEntity> findContingenciesPage(UUID resultUuid, UUID netwo
321321
// HHH000104: firstResult/maxResults specified with collection fetch; applying in memory!
322322
// cf. https://vladmihalcea.com/fix-hibernate-hhh000104-entity-fetch-pagination-warning-message/
323323
// We must separate in two requests, one with pagination the other one with Join Fetch
324+
// Determine which properties to project based on sort fields
325+
// When using DISTINCT, all ORDER BY columns must be in the SELECT list
326+
List<String> projectionProperties = new ArrayList<>();
327+
projectionProperties.add("uuid");
328+
329+
// Add sort properties to projection to satisfy DISTINCT + ORDER BY requirement
330+
for (Sort.Order order : modifiedPageable.getSort()) {
331+
String property = order.getProperty();
332+
if (!property.equals("uuid") && !projectionProperties.contains(property)) {
333+
projectionProperties.add(property);
334+
}
335+
}
324336

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

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

375409
if (!uuidPage.hasContent()) {
376410
// 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)