View Javadoc
1   package ejava.examples.asyncmarket.bo;
2   
3   import java.io.Serializable;
4   import java.util.ArrayList;
5   import java.util.Collection;
6   
7   import javax.persistence.*;
8   
9   @Entity @Table(name="ASYNCMARKET_BIDDER")
10  @NamedQueries({
11      @NamedQuery(name="AsyncMarket_getAllPeople", 
12              query="select p from Person p"),
13      @NamedQuery(name="AsyncMarket_getPersonByUserId", 
14                  query="select p from Person p " +
15                          "where p.userId=:userId")
16  })
17  public class Person implements Serializable {
18      private static final long serialVersionUID = 1L;
19      private long id;
20      private long version;
21      private String userId;
22      private String name;
23      private Collection<Bid> bids = new ArrayList<Bid>();
24      private Collection<AuctionItem> items = new ArrayList<AuctionItem>();
25      
26      public Person() {}
27      public Person(long id) { setId(id); }
28  
29      @Id @GeneratedValue
30      public long getId() {
31          return id;
32      }
33      private void setId(long id) {
34          this.id = id;
35      }
36      @Version
37      public long getVersion() {
38          return version;
39      }
40      public void setVersion(long version) {
41          this.version = version;
42      }
43  
44      @Column(nullable=false, unique=true, updatable=false)
45      public String getUserId() {
46          return userId;
47      }
48      public void setUserId(String userId) {
49          this.userId = userId;
50      }
51      public String getName() {
52          return name;
53      }
54      public void setName(String name) {
55          this.name = name;
56      }
57  
58      @OneToMany(mappedBy="bidder")
59      public Collection<Bid> getBids() {
60          return bids;
61      }
62      public void setBids(Collection<Bid> bids) {
63          this.bids = bids;
64      }
65      
66      @OneToMany(mappedBy="owner")
67      public Collection<AuctionItem> getItems() {
68          return items;
69      }
70      public void setItems(Collection<AuctionItem> items) {
71          this.items = items;
72      }
73      
74      public String toString() {
75          StringBuilder text = new StringBuilder();
76          text.append("id=" + id);
77          text.append(", version=" + version);
78          text.append(", userId=" + userId);
79          text.append(", name=" + name);
80          text.append(", bids(" + bids.size() + ")");
81          text.append(", items(" + items.size() + ")");
82          return text.toString();
83      }
84  }