1 package ejava.projects.esales.bo;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.List;
6
7 import javax.persistence.CascadeType;
8 import javax.persistence.Column;
9 import javax.persistence.Entity;
10 import javax.persistence.Id;
11 import javax.persistence.JoinColumn;
12 import javax.persistence.JoinTable;
13 import javax.persistence.OneToMany;
14 import javax.persistence.Table;
15
16
17
18
19
20
21
22
23
24 @SuppressWarnings("serial")
25 @Entity @Table(name="ESALES_ACCT")
26 public class Account implements Serializable {
27 private String userId;
28 private String firstName;
29 private List<Address> addresses = new ArrayList<Address>();
30
31
32 protected Account() {}
33 public Account(String userId) {
34 setUserId(userId);
35 }
36 public Account(String userId, String firstName, List<Address> addresses) {
37 setUserId(userId);
38 this.firstName = firstName;
39 this.addresses = addresses;
40 }
41
42 @Id @Column(name="USER_ID")
43 public String getUserId() {
44 return userId;
45 }
46 private void setUserId(String userId) {
47 this.userId = userId;
48 }
49
50 @Column(name="FIRST_NAME")
51 public String getFirstName() {
52 return firstName;
53 }
54 public void setFirstName(String firstName) {
55 this.firstName = firstName;
56 }
57
58 @OneToMany(cascade=CascadeType.ALL)
59 @JoinTable(name="ESALES_ACCT_ADDRESS_LINK",
60 joinColumns=@JoinColumn(name="USER_ID"),
61 inverseJoinColumns=@JoinColumn(name="ADDRESS_ID"))
62 public List<Address> getAddresses() {
63 return addresses;
64 }
65 public void setAddresses(List<Address> addresses) {
66 this.addresses = addresses;
67 }
68
69 public String toString() {
70 StringBuilder text = new StringBuilder();
71 text.append("userId=" + userId);
72 text.append(", firstName=" + firstName);
73 text.append(", addresses={");
74 for (Address a : addresses) {
75 text.append("{" + a + "}, ");
76 }
77 text.append("}");
78 return text.toString();
79 }
80 }