1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.tasksJsf;
18
19 import static javax.persistence.CascadeType.ALL;
20 import static javax.persistence.GenerationType.IDENTITY;
21
22 import java.io.Serializable;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.Id;
30 import javax.persistence.OneToMany;
31
32
33
34
35
36
37 @SuppressWarnings("serial")
38 @Entity
39 public class User implements Serializable {
40
41 @Id
42 @GeneratedValue(strategy = IDENTITY)
43 private Long id;
44
45 @Column(unique = true)
46 private String username;
47
48 @OneToMany(cascade = ALL, mappedBy = "owner")
49 @Column(updatable = false)
50 private List<Task> tasks = new ArrayList<Task>();
51
52 public User() {
53 }
54
55 public User(String username) {
56 this.username = username;
57 }
58
59 public Long getId() {
60 return id;
61 }
62
63 public void setId(Long id) {
64 this.id = id;
65 }
66
67 public String getUsername() {
68 return username;
69 }
70
71 public void setUsername(String username) {
72 this.username = username;
73 }
74
75 public List<Task> getTasks() {
76 return tasks;
77 }
78
79 public void setTasks(List<Task> tasks) {
80 this.tasks = tasks;
81 }
82
83 @Override
84 public int hashCode() {
85 final int prime = 31;
86 int result = 1;
87 result = prime * result + ((username == null) ? 0 : username.hashCode());
88 return result;
89 }
90
91 @Override
92 public boolean equals(Object obj) {
93 if (this == obj)
94 return true;
95 if (obj == null)
96 return false;
97 if (getClass() != obj.getClass())
98 return false;
99 User other = (User) obj;
100 if (username == null) {
101 if (other.username != null)
102 return false;
103 } else if (!username.equals(other.username))
104 return false;
105 return true;
106 }
107 }