From b41d9a8ac7071f16d69e87fa29c9ce3aeb8e3cd3 Mon Sep 17 00:00:00 2001 From: Giang Vu Date: Mon, 30 Sep 2024 16:32:46 +1000 Subject: [PATCH] fix: many to many relationship annotations --- backend/src/main/java/org/acme/TimetableResource.java | 4 ++++ backend/src/main/java/org/acme/domain/Room.java | 3 +-- backend/src/main/java/org/acme/domain/Timetable.java | 8 +++++--- backend/src/main/java/org/acme/domain/Unit.java | 3 +-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/org/acme/TimetableResource.java b/backend/src/main/java/org/acme/TimetableResource.java index e6b4241..a7caf6d 100644 --- a/backend/src/main/java/org/acme/TimetableResource.java +++ b/backend/src/main/java/org/acme/TimetableResource.java @@ -36,11 +36,15 @@ public class TimetableResource { private int jobId = 0; @POST + @Transactional public Timetable handleRequest(Timetable problem) throws ExecutionException, InterruptedException { jobId += 1; String name = "Job" + Integer.toString(jobId); + // return problem; + Timetable solution = solverManager.solve(name, problem).getFinalBestSolution(); + solution.persist(); return solution; } diff --git a/backend/src/main/java/org/acme/domain/Room.java b/backend/src/main/java/org/acme/domain/Room.java index 22ea8f7..5e5a048 100644 --- a/backend/src/main/java/org/acme/domain/Room.java +++ b/backend/src/main/java/org/acme/domain/Room.java @@ -37,7 +37,6 @@ public class Room extends PanacheEntity { */ @JsonIgnoreProperties("room") @OneToMany(mappedBy = "room", orphanRemoval = false) - @JsonBackReference @JsonIgnore public List units = new ArrayList(); @@ -46,7 +45,7 @@ public class Room extends PanacheEntity { */ @JsonIgnoreProperties("rooms") @ManyToMany(mappedBy = "rooms", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @JsonManagedReference + // @JsonManagedReference @JsonIgnore public List timetables = new ArrayList(); diff --git a/backend/src/main/java/org/acme/domain/Timetable.java b/backend/src/main/java/org/acme/domain/Timetable.java index 8b98933..b45fb47 100644 --- a/backend/src/main/java/org/acme/domain/Timetable.java +++ b/backend/src/main/java/org/acme/domain/Timetable.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonManagedReference; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Represents a timetable, the solution from the program. @@ -56,9 +57,10 @@ public class Timetable extends PanacheEntity { joinColumns = @JoinColumn(name = "timetable_id"), inverseJoinColumns = @JoinColumn(name = "room_id") ) - @JsonManagedReference + // @JsonManagedReference @ProblemFactCollectionProperty - @JsonIgnore + // @JsonIgnore + // @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @ValueRangeProvider public List rooms; @@ -74,7 +76,7 @@ public class Timetable extends PanacheEntity { joinColumns = @JoinColumn(name = "timetable_id"), inverseJoinColumns = @JoinColumn(name = "unit_id") ) - @JsonManagedReference + // @JsonManagedReference @PlanningEntityCollectionProperty public List units; diff --git a/backend/src/main/java/org/acme/domain/Unit.java b/backend/src/main/java/org/acme/domain/Unit.java index d91c910..16409e1 100644 --- a/backend/src/main/java/org/acme/domain/Unit.java +++ b/backend/src/main/java/org/acme/domain/Unit.java @@ -63,7 +63,6 @@ public class Unit extends PanacheEntity { @JsonIgnoreProperties("units") @ManyToOne(cascade = {CascadeType.ALL}) @JoinColumn(name = "room_id") - @JsonManagedReference @PlanningVariable public Room room; @@ -74,7 +73,7 @@ public class Unit extends PanacheEntity { */ @JsonIgnoreProperties("units") @ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @JsonManagedReference + // @JsonManagedReference @JsonIgnore public List timetables = new ArrayList();