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