1
1
package org .regeneration .sample .Entities ;
2
2
3
+ import org .springframework .beans .factory .annotation .Autowired ;
4
+
3
5
import javax .persistence .*;
4
6
import java .util .Collection ;
7
+ import java .util .Map ;
5
8
import java .util .Objects ;
6
9
7
10
@ Entity
8
11
public class Citizen {
12
+
13
+ @ Id
14
+ @ GeneratedValue (strategy = GenerationType .AUTO )
9
15
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 )
10
21
private int amka ;
22
+
23
+ @ Column (name = "first_name" , length = 32 )
11
24
private String firstName ;
25
+
26
+ @ Column (name = "last_name" , length = 32 )
12
27
private String lastName ;
28
+
29
+ @ Column (name = "email" , nullable = false , length = 50 )
13
30
private String email ;
14
- private String phoneNumner ;
15
- private Collection <Appointment > appointmentsById ;
16
- private User userById ;
17
31
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
+
20
55
public int getId () {
21
56
return id ;
22
57
}
@@ -25,8 +60,14 @@ public void setId(int id) {
25
60
this .id = id ;
26
61
}
27
62
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
+
30
71
public int getAmka () {
31
72
return amka ;
32
73
}
@@ -35,8 +76,6 @@ public void setAmka(int amka) {
35
76
this .amka = amka ;
36
77
}
37
78
38
- @ Basic
39
- @ Column (name = "first_name" , nullable = true , length = 32 )
40
79
public String getFirstName () {
41
80
return firstName ;
42
81
}
@@ -45,8 +84,6 @@ public void setFirstName(String firstName) {
45
84
this .firstName = firstName ;
46
85
}
47
86
48
- @ Basic
49
- @ Column (name = "last_name" , nullable = true , length = 32 )
50
87
public String getLastName () {
51
88
return lastName ;
52
89
}
@@ -55,8 +92,6 @@ public void setLastName(String lastName) {
55
92
this .lastName = lastName ;
56
93
}
57
94
58
- @ Basic
59
- @ Column (name = "email" , nullable = false , length = 50 )
60
95
public String getEmail () {
61
96
return email ;
62
97
}
@@ -65,14 +100,28 @@ public void setEmail(String email) {
65
100
this .email = email ;
66
101
}
67
102
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 ;
72
117
}
73
118
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 ;
76
125
}
77
126
78
127
@ Override
@@ -81,34 +130,17 @@ public boolean equals(Object o) {
81
130
if (o == null || getClass () != o .getClass ()) return false ;
82
131
Citizen citizen = (Citizen ) o ;
83
132
return id == citizen .id &&
133
+ userId == citizen .userId &&
84
134
amka == citizen .amka &&
85
135
Objects .equals (firstName , citizen .firstName ) &&
86
136
Objects .equals (lastName , citizen .lastName ) &&
87
137
Objects .equals (email , citizen .email ) &&
88
- Objects .equals (phoneNumner , citizen .phoneNumner );
138
+ Objects .equals (phoneNumber , citizen .phoneNumber );
89
139
}
90
140
91
141
@ Override
92
142
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 );
99
144
}
100
145
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
- }
114
146
}
0 commit comments