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 20 @Id @GeneratedValue(strategy=GenerationType.IDENTITY) 21 private long id; 22 23 @Version 24 private long version; 25 26 @Column(length=32, nullable=false, unique=true, updatable=false) 27 private String userId; 28 29 @Column(length=32) 30 private String name; 31 32 @OneToMany(mappedBy="bidder", 33 fetch=FetchType.LAZY, 34 cascade={CascadeType.PERSIST, 35 CascadeType.REMOVE}) 36 private Collection<Bid> bids = new ArrayList<>(); 37 38 @OneToMany(mappedBy="owner", 39 fetch=FetchType.LAZY, 40 cascade={CascadeType.PERSIST, 41 CascadeType.REMOVE}) 42 private Collection<AuctionItem> items = new ArrayList<>(); 43 44 public Person() {} 45 public Person(long id) { setId(id); } 46 47 public long getId() { 48 return id; 49 } 50 private void setId(long id) { 51 this.id = id; 52 } 53 54 public long getVersion() { 55 return version; 56 } 57 public void setVersion(long version) { 58 this.version = version; 59 } 60 61 public String getUserId() { 62 return userId; 63 } 64 public void setUserId(String userId) { 65 this.userId = userId; 66 } 67 68 public String getName() { 69 return name; 70 } 71 public void setName(String name) { 72 this.name = name; 73 } 74 75 public Collection<Bid> getBids() { 76 return bids; 77 } 78 public void setBids(Collection<Bid> bids) { 79 this.bids = bids; 80 } 81 82 public Collection<AuctionItem> getItems() { 83 return items; 84 } 85 public void setItems(Collection<AuctionItem> items) { 86 this.items = items; 87 } 88 89 public String toString() { 90 StringBuilder text = new StringBuilder(); 91 text.append("id=" + id); 92 text.append(", version=" + version); 93 text.append(", userId=" + userId); 94 text.append(", name=" + name); 95 text.append(", bids(" + bids.size() + ")"); 96 text.append(", items(" + items.size() + ")"); 97 return text.toString(); 98 } 99 }