Skip to content

Commit 3a5bcf0

Browse files
committed
JPA Working
1 parent 1ca4e6f commit 3a5bcf0

File tree

11 files changed

+332
-156
lines changed

11 files changed

+332
-156
lines changed

sample/src/main/java/org/regeneration/sample/Entities/Appointment.java

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,33 @@
66

77
@Entity
88
public class Appointment {
9+
@Id
10+
@Column(name = "id", nullable = false)
911
private int id;
12+
13+
@Column(name = "citizen_id", nullable = false, insertable = false, updatable = false)
1014
private int citizenId;
15+
16+
@Column(name = "doctor_id", nullable = false, insertable = false, updatable = false)
1117
private int doctorId;
12-
private Timestamp appointmentDatetime;
18+
19+
@Column(name = "datetime", nullable = false)
20+
private Timestamp datetime;
21+
22+
@Column(name = "description", nullable = true, columnDefinition = "TEXT")
1323
private String description;
24+
25+
@Column(name = "notes", nullable = true, columnDefinition = "TEXT")
1426
private String notes;
15-
private Citizen citizenByCitizenId;
16-
private Doctor doctorByDoctorId;
1727

18-
@Id
19-
@Column(name = "id", nullable = false)
28+
@ManyToOne
29+
@JoinColumn(name = "citizen_id", referencedColumnName = "id", nullable = false)
30+
private Citizen citizen;
31+
32+
@ManyToOne
33+
@JoinColumn(name = "doctor_id", referencedColumnName = "id", nullable = false)
34+
private Doctor doctor;
35+
2036
public int getId() {
2137
return id;
2238
}
@@ -25,8 +41,6 @@ public void setId(int id) {
2541
this.id = id;
2642
}
2743

28-
@Basic
29-
@Column(name = "citizen_id", nullable = false, insertable = false, updatable = false)
3044
public int getCitizenId() {
3145
return citizenId;
3246
}
@@ -35,8 +49,6 @@ public void setCitizenId(int citizenId) {
3549
this.citizenId = citizenId;
3650
}
3751

38-
@Basic
39-
@Column(name = "doctor_id", nullable = false, insertable = false, updatable = false)
4052
public int getDoctorId() {
4153
return doctorId;
4254
}
@@ -45,18 +57,14 @@ public void setDoctorId(int doctorId) {
4557
this.doctorId = doctorId;
4658
}
4759

48-
@Basic
49-
@Column(name = "appointment_datetime", nullable = false)
50-
public Timestamp getAppointmentDatetime() {
51-
return appointmentDatetime;
60+
public Timestamp getDatetime() {
61+
return datetime;
5262
}
5363

54-
public void setAppointmentDatetime(Timestamp appointmentDatetime) {
55-
this.appointmentDatetime = appointmentDatetime;
64+
public void setDatetime(Timestamp datetime) {
65+
this.datetime = datetime;
5666
}
5767

58-
@Basic
59-
@Column(name = "description", nullable = true)
6068
public String getDescription() {
6169
return description;
6270
}
@@ -65,8 +73,6 @@ public void setDescription(String description) {
6573
this.description = description;
6674
}
6775

68-
@Basic
69-
@Column(name = "notes", nullable = true)
7076
public String getNotes() {
7177
return notes;
7278
}
@@ -83,33 +89,29 @@ public boolean equals(Object o) {
8389
return id == that.id &&
8490
citizenId == that.citizenId &&
8591
doctorId == that.doctorId &&
86-
Objects.equals(appointmentDatetime, that.appointmentDatetime) &&
92+
Objects.equals(datetime, that.datetime) &&
8793
Objects.equals(description, that.description) &&
8894
Objects.equals(notes, that.notes);
8995
}
9096

9197
@Override
9298
public int hashCode() {
93-
return Objects.hash(id, citizenId, doctorId, appointmentDatetime, description, notes);
99+
return Objects.hash(id, citizenId, doctorId, datetime, description, notes);
94100
}
95101

96-
@ManyToOne
97-
@JoinColumn(name = "citizen_id", referencedColumnName = "id", nullable = false)
98-
public Citizen getCitizenByCitizenId() {
99-
return citizenByCitizenId;
102+
public Citizen getCitizen() {
103+
return citizen;
100104
}
101105

102-
public void setCitizenByCitizenId(Citizen citizenByCitizenId) {
103-
this.citizenByCitizenId = citizenByCitizenId;
106+
public void setCitizenByCitizenId(Citizen citizen) {
107+
this.citizen = citizen;
104108
}
105109

106-
@ManyToOne
107-
@JoinColumn(name = "doctor_id", referencedColumnName = "id", nullable = false)
108110
public Doctor getDoctorByDoctorId() {
109-
return doctorByDoctorId;
111+
return doctor;
110112
}
111113

112-
public void setDoctorByDoctorId(Doctor doctorByDoctorId) {
113-
this.doctorByDoctorId = doctorByDoctorId;
114+
public void setDoctorByDoctorId(Doctor doctor) {
115+
this.doctor = doctor;
114116
}
115117
}
Lines changed: 71 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
11
package org.regeneration.sample.Entities;
22

3+
import org.springframework.beans.factory.annotation.Autowired;
4+
35
import javax.persistence.*;
46
import java.util.Collection;
7+
import java.util.Map;
58
import java.util.Objects;
69

710
@Entity
811
public class Citizen {
12+
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.AUTO)
915
private int id;
16+
17+
@Column(name = "user_id", nullable = false, insertable = false, updatable = false)
18+
private int userId;
19+
20+
@Column(name = "amka", nullable = false, unique = true)
1021
private int amka;
22+
23+
@Column(name = "first_name", length = 32)
1124
private String firstName;
25+
26+
@Column(name = "last_name", length = 32)
1227
private String lastName;
28+
29+
@Column(name = "email", nullable = false, length = 50)
1330
private String email;
14-
private String phoneNumner;
15-
private Collection<Appointment> appointmentsById;
16-
private User userById;
1731

18-
@Id
19-
@Column(name = "id", nullable = false)
32+
@Column(name = "phone_number", length = 11)
33+
private String phoneNumber;
34+
35+
@OneToMany(mappedBy = "citizen")
36+
private Collection<Appointment> appointments;
37+
38+
@OneToOne
39+
@JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false)
40+
private User user;
41+
42+
public Citizen() {
43+
}
44+
45+
public Citizen(User user, int amka, String firstName, String lastName, String email, String phoneNumber) {
46+
this.user = user;
47+
this.amka = amka;
48+
this.firstName = firstName;
49+
this.lastName = lastName;
50+
this.email = email;
51+
this.phoneNumber = phoneNumber;
52+
}
53+
54+
2055
public int getId() {
2156
return id;
2257
}
@@ -25,8 +60,14 @@ public void setId(int id) {
2560
this.id = id;
2661
}
2762

28-
@Basic
29-
@Column(name = "AMKA", nullable = false)
63+
public int getUserId() {
64+
return userId;
65+
}
66+
67+
public void setUserId(int userId) {
68+
this.userId = userId;
69+
}
70+
3071
public int getAmka() {
3172
return amka;
3273
}
@@ -35,8 +76,6 @@ public void setAmka(int amka) {
3576
this.amka = amka;
3677
}
3778

38-
@Basic
39-
@Column(name = "first_name", nullable = true, length = 32)
4079
public String getFirstName() {
4180
return firstName;
4281
}
@@ -45,8 +84,6 @@ public void setFirstName(String firstName) {
4584
this.firstName = firstName;
4685
}
4786

48-
@Basic
49-
@Column(name = "last_name", nullable = true, length = 32)
5087
public String getLastName() {
5188
return lastName;
5289
}
@@ -55,8 +92,6 @@ public void setLastName(String lastName) {
5592
this.lastName = lastName;
5693
}
5794

58-
@Basic
59-
@Column(name = "email", nullable = false, length = 50)
6095
public String getEmail() {
6196
return email;
6297
}
@@ -65,14 +100,28 @@ public void setEmail(String email) {
65100
this.email = email;
66101
}
67102

68-
@Basic
69-
@Column(name = "phone_numner", nullable = true, length = 11)
70-
public String getPhoneNumner() {
71-
return phoneNumner;
103+
public String getPhoneNumber() {
104+
return phoneNumber;
105+
}
106+
107+
public void setPhoneNumber(String phoneNumber) {
108+
this.phoneNumber = phoneNumber;
109+
}
110+
111+
public Collection<Appointment> getAppointmentsById() {
112+
return appointments;
113+
}
114+
115+
public void setAppointmentsById(Collection<Appointment> appointments) {
116+
this.appointments = appointments;
72117
}
73118

74-
public void setPhoneNumner(String phoneNumner) {
75-
this.phoneNumner = phoneNumner;
119+
public User getUser() {
120+
return user;
121+
}
122+
123+
public void setUser(User user) {
124+
this.user = user;
76125
}
77126

78127
@Override
@@ -81,34 +130,17 @@ public boolean equals(Object o) {
81130
if (o == null || getClass() != o.getClass()) return false;
82131
Citizen citizen = (Citizen) o;
83132
return id == citizen.id &&
133+
userId == citizen.userId &&
84134
amka == citizen.amka &&
85135
Objects.equals(firstName, citizen.firstName) &&
86136
Objects.equals(lastName, citizen.lastName) &&
87137
Objects.equals(email, citizen.email) &&
88-
Objects.equals(phoneNumner, citizen.phoneNumner);
138+
Objects.equals(phoneNumber, citizen.phoneNumber);
89139
}
90140

91141
@Override
92142
public int hashCode() {
93-
return Objects.hash(id, amka, firstName, lastName, email, phoneNumner);
94-
}
95-
96-
@OneToMany(mappedBy = "citizenByCitizenId")
97-
public Collection<Appointment> getAppointmentsById() {
98-
return appointmentsById;
143+
return Objects.hash(id, userId, amka, firstName, lastName, email, phoneNumber);
99144
}
100145

101-
public void setAppointmentsById(Collection<Appointment> appointmentsById) {
102-
this.appointmentsById = appointmentsById;
103-
}
104-
105-
@OneToOne
106-
@JoinColumn(name = "id", referencedColumnName = "id", nullable = false)
107-
public User getUserById() {
108-
return userById;
109-
}
110-
111-
public void setUserById(User userById) {
112-
this.userById = userById;
113-
}
114146
}

0 commit comments

Comments
 (0)