|
1 | 1 | package edu.tamu.app.model; |
2 | 2 |
|
| 3 | +import static javax.persistence.CascadeType.DETACH; |
| 4 | +import static javax.persistence.CascadeType.PERSIST; |
3 | 5 | import static javax.persistence.CascadeType.REFRESH; |
4 | 6 | import static javax.persistence.CascadeType.REMOVE; |
5 | 7 | import static javax.persistence.FetchType.EAGER; |
6 | 8 |
|
7 | 9 | import java.util.ArrayList; |
8 | | -import java.util.HashSet; |
9 | 10 | import java.util.List; |
10 | | -import java.util.Set; |
11 | 11 |
|
12 | 12 | import javax.persistence.Column; |
13 | 13 | import javax.persistence.ElementCollection; |
@@ -56,19 +56,20 @@ public class Service extends BaseEntity { |
56 | 56 |
|
57 | 57 | @Column(nullable = false) |
58 | 58 | private Boolean onShortList; |
59 | | - |
| 59 | + |
60 | 60 | @Lob |
61 | 61 | @Column(nullable = true) |
62 | 62 | private String description; |
63 | 63 |
|
64 | | - @OneToMany(fetch = EAGER, cascade = { REFRESH, REMOVE }, mappedBy = "service") |
| 64 | + @OneToMany(fetch = EAGER, cascade = { DETACH, REMOVE, PERSIST, REFRESH }, mappedBy = "service") |
| 65 | + @Fetch(FetchMode.SELECT) |
65 | 66 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, scope = Note.class, property = "id") |
66 | 67 | @JsonIdentityReference(alwaysAsId = true) |
67 | | - private Set<Note> notes; |
| 68 | + private List<Note> notes; |
68 | 69 |
|
69 | 70 | public Service() { |
70 | 71 | setModelValidator(new ServiceValidator()); |
71 | | - setNotes(new HashSet<Note>()); |
| 72 | + setNotes(new ArrayList<Note>()); |
72 | 73 | setAliases(new ArrayList<String>()); |
73 | 74 | } |
74 | 75 |
|
@@ -115,16 +116,20 @@ public void setServiceUrl(String serviceUrl) { |
115 | 116 | this.serviceUrl = serviceUrl; |
116 | 117 | } |
117 | 118 |
|
118 | | - public Set<Note> getNotes() { |
| 119 | + public List<Note> getNotes() { |
119 | 120 | return notes; |
120 | 121 | } |
121 | 122 |
|
122 | | - public void setNotes(Set<Note> notes) { |
| 123 | + public void setNotes(List<Note> notes) { |
123 | 124 | this.notes = notes; |
124 | 125 | } |
125 | 126 |
|
126 | 127 | public void addNote(Note note) { |
127 | | - this.notes.add(note); |
| 128 | + System.out.println("addNote size before: " + this.notes.size()); |
| 129 | + if (!this.notes.contains(note)) { |
| 130 | + this.notes.add(note); |
| 131 | + } |
| 132 | + System.out.println("addNote size after: " + this.notes.size()); |
128 | 133 | } |
129 | 134 |
|
130 | 135 | public void removeNote(Note note) { |
|
0 commit comments