1 package ejava.examples.asyncmarket.bo; 2 3 import java.io.Serializable; 4 5 import javax.persistence.*; 6 7 @Entity @Table(name="ASYNCMARKET_ORDER") 8 @NamedQueries({ 9 @NamedQuery(name="AsyncMarket_getOrders", 10 query="select o from Order o"), 11 @NamedQuery(name="AsyncMarket_getOrdersForItem", 12 query="select o from Order o " + 13 "where o.item.id = :itemId") 14 }) 15 public class Order implements Serializable { 16 private static final long serialVersionUID = 1L; 17 18 @Id @GeneratedValue(strategy=GenerationType.IDENTITY) 19 private long id; 20 21 @Version 22 private long version; 23 24 @ManyToOne(optional=false, fetch=FetchType.EAGER) 25 private Person buyer; 26 27 @ManyToOne(optional=false, fetch=FetchType.EAGER) 28 private AuctionItem item; 29 30 private double maxBid; 31 32 public Order() {} 33 public Order(long id) { setId(id); } 34 35 public long getId() { 36 return id; 37 } 38 public void setId(long id) { 39 this.id = id; 40 } 41 42 public long getVersion() { 43 return version; 44 } 45 public void setVersion(long version) { 46 this.version = version; 47 } 48 49 public Person getBuyer() { 50 return buyer; 51 } 52 public void setBuyer(Person buyer) { 53 this.buyer = buyer; 54 } 55 56 public AuctionItem getItem() { 57 return item; 58 } 59 public void setItem(AuctionItem item) { 60 this.item = item; 61 } 62 63 public double getMaxBid() { 64 return maxBid; 65 } 66 public void setMaxBid(double maxBid) { 67 this.maxBid = maxBid; 68 } 69 70 public String toString() { 71 StringBuilder text = new StringBuilder(); 72 text.append("id=" + id); 73 text.append(", version=" + version); 74 text.append(", maxBid=" + maxBid); 75 text.append(", buyer=" + buyer.getUserId()); 76 text.append(", item=" + item); 77 text.append(", highestBid=" + item.getHighestBid()); 78 return text.toString(); 79 } 80 }