| .. | .. |
|---|
| 4 | 4 | import java.util.ArrayList; |
|---|
| 5 | 5 | import java.util.Date; |
|---|
| 6 | 6 | import java.util.List; |
|---|
| 7 | +import java.util.Set; |
|---|
| 7 | 8 | |
|---|
| 9 | +import javax.persistence.CascadeType; |
|---|
| 8 | 10 | import javax.persistence.Column; |
|---|
| 9 | 11 | import javax.persistence.Entity; |
|---|
| 10 | 12 | import javax.persistence.GeneratedValue; |
|---|
| .. | .. |
|---|
| 15 | 17 | import javax.persistence.ManyToOne; |
|---|
| 16 | 18 | import javax.persistence.NamedQueries; |
|---|
| 17 | 19 | import javax.persistence.NamedQuery; |
|---|
| 20 | +import javax.persistence.OneToMany; |
|---|
| 18 | 21 | import javax.persistence.Table; |
|---|
| 19 | 22 | |
|---|
| 20 | 23 | import org.codehaus.jackson.annotate.JsonAutoDetect; |
|---|
| .. | .. |
|---|
| 33 | 36 | @Entity |
|---|
| 34 | 37 | @Table(name = "organization") |
|---|
| 35 | 38 | @NamedQueries( |
|---|
| 36 | | - { @NamedQuery(name = "list-organizations", query = "SELECT o FROM Organization o") }) |
|---|
| 39 | + { @NamedQuery(name = "list-organizations", query = "SELECT o FROM Organization o"), @NamedQuery(name = "find-children-org", query = "SELECT o FROM Organization o where o.parentOrganization = :parentOrganization") }) |
|---|
| 37 | 40 | public class Organization implements Serializable { |
|---|
| 38 | 41 | |
|---|
| 39 | 42 | @SuppressWarnings("unused") |
|---|
| .. | .. |
|---|
| 54 | 57 | |
|---|
| 55 | 58 | @JsonIgnore |
|---|
| 56 | 59 | // We don't include the users to limit the size of each row a the listing |
|---|
| 57 | | - @ManyToMany |
|---|
| 60 | + @ManyToMany(cascade = CascadeType.REMOVE) |
|---|
| 58 | 61 | @JoinTable(name = "user_organization", // |
|---|
| 59 | 62 | joinColumns = |
|---|
| 60 | 63 | { @JoinColumn(name = "organization_id", referencedColumnName = "id") }, // |
|---|
| .. | .. |
|---|
| 67 | 70 | @ManyToOne |
|---|
| 68 | 71 | @JoinColumn(name = "org_parent_id") |
|---|
| 69 | 72 | private Organization parentOrganization; |
|---|
| 73 | + |
|---|
| 74 | + @JsonIgnore |
|---|
| 75 | + // We don't include the users to limit the size of each row a the listing |
|---|
| 76 | + @OneToMany(mappedBy = "parentOrganization") |
|---|
| 77 | + private Set<Organization> childOrganizations; |
|---|
| 70 | 78 | |
|---|
| 71 | 79 | public int getId() { |
|---|
| 72 | 80 | return id; |
|---|
| .. | .. |
|---|
| 163 | 171 | return ids; |
|---|
| 164 | 172 | } |
|---|
| 165 | 173 | |
|---|
| 174 | + public Set<Organization> getChildOrganizations() { |
|---|
| 175 | + return childOrganizations; |
|---|
| 176 | + } |
|---|
| 177 | + |
|---|
| 178 | + public void setChildOrganizations(Set<Organization> childOrganizations) { |
|---|
| 179 | + this.childOrganizations = childOrganizations; |
|---|
| 180 | + } |
|---|
| 181 | + |
|---|
| 166 | 182 | } |
|---|