From 0af4e538a115c9a95c1bdda539362bbdadbda6d7 Mon Sep 17 00:00:00 2001 From: Nico Athanassiadis Date: Wed, 13 Nov 2024 12:00:03 +0100 Subject: [PATCH] Fix intermittent sorting of criterion to actual order When you tried to edit a grading template in "Project management" -> "Grading Templates" the criterion could be shown in an order not reflecting the sortOrder of the criterion. The reason was that we only got the arbitrary order depending on the insertion order in the database. Changed the Collection to a List, it is now an ArrayList. Also added @OrderBy("sortOrder ASC") to actually sort by the order of the criterion thus ensuring visual order is intact. --- .../java/se/su/dsv/scipro/report/GradingReportTemplate.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/se/su/dsv/scipro/report/GradingReportTemplate.java b/core/src/main/java/se/su/dsv/scipro/report/GradingReportTemplate.java index f8b5c9c8c3..55fe04823b 100644 --- a/core/src/main/java/se/su/dsv/scipro/report/GradingReportTemplate.java +++ b/core/src/main/java/se/su/dsv/scipro/report/GradingReportTemplate.java @@ -10,6 +10,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; +import jakarta.persistence.OrderBy; import jakarta.persistence.Table; import jakarta.persistence.Temporal; import jakarta.persistence.TemporalType; @@ -22,7 +23,6 @@ import se.su.dsv.scipro.system.User; import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -62,7 +62,8 @@ public class GradingReportTemplate extends DomainObject { // JPA-mappings of other tables referencing to this table "grading_report_template" // ---------------------------------------------------------------------------------- @OneToMany(mappedBy = "gradingReportTemplate", cascade = {CascadeType.ALL}, orphanRemoval = true) - private Collection criteria = new HashSet<>(); + @OrderBy("sortOrder ASC") + private List criteria = new ArrayList<>(); @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = "grading_report_template_id", referencedColumnName = "id") -- 2.39.5