1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.imca.model.entities;
17
18 import javax.persistence.Entity;
19 import javax.persistence.GeneratedValue;
20 import javax.persistence.GenerationType;
21 import javax.persistence.Id;
22 import javax.persistence.NamedQueries;
23 import javax.persistence.NamedQuery;
24 import javax.persistence.OneToOne;
25
26
27
28
29
30
31
32
33 @Entity
34 @NamedQueries ({
35 @NamedQuery(name = "MembershipBasicSearch",
36 query = "SELECT m FROM MembershipEntity m WHERE " +
37 "m.note LIKE :search"),
38 @NamedQuery(name = "findActiveMembersOnDate",
39 query = "SELECT m FROM MembershipEntity m WHERE " +
40 "m.type.validFrom <= :date AND m.type.validTo >= :date " +
41 "AND m.paid = true " +
42 "ORDER BY m.person.firstName, m.person.lastName"),
43 @NamedQuery(name = "findMembersForMembershipType",
44 query = "SELECT m FROM MembershipEntity m WHERE " +
45 "m.type = :membershipType"),
46 @NamedQuery(name = "findMembershipsForPerson",
47 query = "SELECT m FROM MembershipEntity m WHERE " +
48 "m.person = :person")
49 })
50 public class MembershipEntity {
51
52
53
54
55 @Id
56 @GeneratedValue(strategy=GenerationType.TABLE)
57 private long id;
58
59 @OneToOne
60 private MembershipTypeEntity type;
61
62 @OneToOne
63 private FeeEntity fee;
64
65 @OneToOne
66 private PersonEntity person;
67
68 private String note = "";
69
70 private boolean paid = false;
71
72 public FeeEntity getFee() {
73 return fee;
74 }
75
76 public void setFee(FeeEntity fee) {
77 this.fee = fee;
78 }
79
80 public long getId() {
81 return id;
82 }
83
84 public void setId(long id) {
85 this.id = id;
86 }
87
88 public boolean getPaid() {
89 return paid;
90 }
91
92 public void setPaid(boolean paid) {
93 this.paid = paid;
94 }
95
96 public PersonEntity getPerson() {
97 return person;
98 }
99
100 public void setPerson(PersonEntity person) {
101 this.person = person;
102 }
103
104 public MembershipTypeEntity getType() {
105 return type;
106 }
107
108 public void setType(MembershipTypeEntity type) {
109 this.type = type;
110 }
111
112
113
114
115
116 public String toString(){
117 if (person == null || type == null) {
118 return this.getId() + "";
119 }
120 return person.getFirstName() + " " + person.getLastName() + " - " +
121 type.toString();
122 }
123
124 public String getNote() {
125 return note;
126 }
127
128 public void setNote(String note) {
129 this.note = note;
130 }
131 }