Skip to content

Commit

Permalink
fix: many to many relationship annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dh-giang-vu committed Sep 30, 2024
1 parent ce6cc2c commit b41d9a8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions backend/src/main/java/org/acme/TimetableResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions backend/src/main/java/org/acme/domain/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class Room extends PanacheEntity {
*/
@JsonIgnoreProperties("room")
@OneToMany(mappedBy = "room", orphanRemoval = false)
@JsonBackReference
@JsonIgnore
public List<Unit> units = new ArrayList<Unit>();

Expand All @@ -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<Timetable> timetables = new ArrayList<Timetable>();

Expand Down
8 changes: 5 additions & 3 deletions backend/src/main/java/org/acme/domain/Timetable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Room> rooms;

Expand All @@ -74,7 +76,7 @@ public class Timetable extends PanacheEntity {
joinColumns = @JoinColumn(name = "timetable_id"),
inverseJoinColumns = @JoinColumn(name = "unit_id")
)
@JsonManagedReference
// @JsonManagedReference
@PlanningEntityCollectionProperty
public List<Unit> units;

Expand Down
3 changes: 1 addition & 2 deletions backend/src/main/java/org/acme/domain/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public class Unit extends PanacheEntity {
@JsonIgnoreProperties("units")
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name = "room_id")
@JsonManagedReference
@PlanningVariable
public Room room;

Expand All @@ -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<Timetable> timetables = new ArrayList<Timetable>();

Expand Down

0 comments on commit b41d9a8

Please sign in to comment.