View Javadoc
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   * This is an example eSales Account class. It will use full JPA annotations
18   * to define the mappings to the database. We could have also used an orm.xml
19   * file supplied by the DAO.
20   *
21   */
22  @SuppressWarnings("serial")
23  @Entity @Table(name="ESALES_ACCT")
24  public class Account implements Serializable {
25      @Id @Column(name="USER_ID", length=20)
26  	private String userId;
27  
28      @Column(name="FIRST_NAME", length=20)
29  	private String firstName;
30  
31  	@OneToMany(cascade=CascadeType.ALL)
32      @JoinTable(name="ESALES_ACCT_ADDRESS_LINK",
33              joinColumns=@JoinColumn(name="USER_ID"),
34              inverseJoinColumns=@JoinColumn(name="ADDRESS_ID"))
35  	private List<Address> addresses = new ArrayList<Address>();
36  	
37  
38  	public Account() {}   //JPA requires a no-arg ctor
39  	public Account(String userId) {
40  		setUserId(userId);
41  	}
42  	public Account(String userId, String firstName, List<Address> addresses) {
43  		setUserId(userId);
44  		this.firstName = firstName;
45  		this.addresses = addresses;
46  	}
47  	
48  	public String getUserId() {
49  		return userId;
50  	}
51  	private void setUserId(String userId) {
52  		this.userId = userId;
53  	}
54  
55  	public String getFirstName() {
56  		return firstName;
57  	}
58  	public void setFirstName(String firstName) {
59  		this.firstName = firstName;
60  	}
61  
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  }