From e6f74b5a2e3f12ff8cf3d448c1e23227627acb82 Mon Sep 17 00:00:00 2001 From: Abdelsalem Date: Wed, 5 Nov 2025 13:15:26 +0100 Subject: [PATCH] springboot3.5.6 Signed-off-by: Abdelsalem --- pom.xml | 2 +- ...ncyLimitViolationSpecificationBuilder.java | 2 +- .../SecurityAnalysisResultService.java | 58 +++++++++++++++---- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 92e00523..c305801f 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ powsybl/java-dynawo:3.0.0 - 44.0.0 + 44.1.0-SNAPSHOT org.gridsuite.securityanalysis.server 1.0.5 5.0.0-alpha.14 diff --git a/src/main/java/org/gridsuite/securityanalysis/server/repositories/specifications/PreContingencyLimitViolationSpecificationBuilder.java b/src/main/java/org/gridsuite/securityanalysis/server/repositories/specifications/PreContingencyLimitViolationSpecificationBuilder.java index 95352866..9ba10047 100644 --- a/src/main/java/org/gridsuite/securityanalysis/server/repositories/specifications/PreContingencyLimitViolationSpecificationBuilder.java +++ b/src/main/java/org/gridsuite/securityanalysis/server/repositories/specifications/PreContingencyLimitViolationSpecificationBuilder.java @@ -25,7 +25,7 @@ public Specification resultUuidEquals(UUID v } public Specification buildSpecification(UUID resultUuid, List resourceFilters) { - Specification specification = Specification.where(resultUuidEquals(resultUuid)); + Specification specification = resultUuidEquals(resultUuid); return SpecificationUtils.appendFiltersToSpecification(specification, resourceFilters); } diff --git a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisResultService.java b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisResultService.java index 3be710fc..50d97a18 100644 --- a/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisResultService.java +++ b/src/main/java/org/gridsuite/securityanalysis/server/service/SecurityAnalysisResultService.java @@ -319,14 +319,30 @@ public Page findContingenciesPage(UUID resultUuid, UUID netwo // HHH000104: firstResult/maxResults specified with collection fetch; applying in memory! // cf. https://vladmihalcea.com/fix-hibernate-hhh000104-entity-fetch-pagination-warning-message/ // We must separate in two requests, one with pagination the other one with Join Fetch + // Determine which properties to project based on sort fields + // When using DISTINCT, all ORDER BY columns must be in the SELECT list + List projectionProperties = new ArrayList<>(); + projectionProperties.add("uuid"); + + // Add sort properties to projection to satisfy DISTINCT + ORDER BY requirement + for (Sort.Order order : modifiedPageable.getSort()) { + String property = order.getProperty(); + if (!property.equals("uuid") && !projectionProperties.contains(property)) { + projectionProperties.add(property); + } + } // First, we fetch contingencies UUIDs, with all the filters and pagination - Page uuidPage = contingencyRepository.findBy(specification, q -> - q.project("uuid") - .as(ContingencyRepository.EntityUuid.class) - .sortBy(modifiedPageable.getSort()) - .page(modifiedPageable) - ); + Page uuidPage = contingencyRepository.findBy(specification, q -> { + var query = q.as(ContingencyRepository.EntityUuid.class) + .sortBy(modifiedPageable.getSort()); + if (projectionProperties.size() == 1) { + query = query.project("uuid"); + } else { + query = query.project(projectionProperties.toArray(new String[0])); + } + return query.page(modifiedPageable); + }); if (!uuidPage.hasContent()) { // 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 findSubjectLimitViolationsPage(UUID res // HHH000104: firstResult/maxResults specified with collection fetch; applying in memory! // cf. https://vladmihalcea.com/fix-hibernate-hhh000104-entity-fetch-pagination-warning-message/ // We must separate in two requests, one with pagination the other one with Join Fetch - Page uuidPage = subjectLimitViolationRepository.findBy(specification, q -> - q.project("id") - .as(SubjectLimitViolationRepository.EntityId.class) - .sortBy(modifiedPageable.getSort()) - .page(modifiedPageable) - ); + + // Determine which properties to project based on sort fields + // When using DISTINCT, all ORDER BY columns must be in the SELECT list + List projectionProperties = new ArrayList<>(); + projectionProperties.add("id"); + + // Add sort properties to projection to satisfy DISTINCT + ORDER BY requirement + for (Sort.Order order : modifiedPageable.getSort()) { + String property = order.getProperty(); + if (!property.equals("id") && !projectionProperties.contains(property)) { + projectionProperties.add(property); + } + } + + Page uuidPage = subjectLimitViolationRepository.findBy(specification, q -> { + var query = q.as(SubjectLimitViolationRepository.EntityId.class) + .sortBy(modifiedPageable.getSort()); + if (projectionProperties.size() == 1) { + query = query.project("id"); + } else { + query = query.project(projectionProperties.toArray(new String[0])); + } + return query.page(modifiedPageable); + }); if (!uuidPage.hasContent()) { // Since springboot 3.2, the return value of Page.empty() is not serializable. See https://github.com/spring-projects/spring-data-commons/issues/2987