-
Notifications
You must be signed in to change notification settings - Fork 5
/
User.java
103 lines (93 loc) · 2.71 KB
/
User.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.doing.more.java.example;/*
* The Many-To-Many relationship between User and PhoneNumber objects requires two tables
* app_user and phone_number with a transition table user_number that maps phone numbers to users.
* The @ManyToMany annotation shows how to make the User object aware of its phone numbers.
*/
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
@Entity
@Table(name = "app_user")
public class User {
@Id
@GeneratedValue
private Integer id;
private String uname;
private String pword;
private int active;
private int manager_level;
private String session;
/*
* one User can have many phone numbers. CascadeType.ALL causes associated
* phone numbers to be deleted when a User is deleted.
*/
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(
name="user_number",
joinColumns = { @JoinColumn( name="user_id") },
inverseJoinColumns = @JoinColumn( name="phone_id")
)
private Set<PhoneNumber> phoneNumbers;
public User() {
this.active = 1;
this.manager_level = 0;
this.session = "";
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", uname='" + uname + '\'' +
", pword='" + pword + '\'' +
", active=" + active +
", manager_level=" + manager_level +
", session='" + session + '\'' +
", phoneNumbers=" + phoneNumbers +
'}';
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPword() {
return pword;
}
public void setPword(String pword) {
this.pword = pword;
}
public Set<PhoneNumber> getPhoneNumbers() {
return phoneNumbers;
}
public int getManager_level() {
return manager_level;
}
public void setManager_level(int manager_level) {
this.manager_level = manager_level;
}
public String getSession() {
return session;
}
public void setSession(String session) {
this.session = session;
}
public void setActive(int anIndicator){
this.active = anIndicator;
}
public int getActive(){
return this.active;
}
}