1 package ejava.examples.asyncmarket.bo; 2 3 import java.io.Serializable; 4 5 import javax.persistence.*; 6 7 @Entity @Table(name="ASYNCMARKET_BID") 8 public class Bid implements Serializable{ 9 private static final long serialVersionUID = 1L; 10 11 @Id @GeneratedValue(strategy=GenerationType.IDENTITY) 12 private long id; 13 14 @Column(scale=7, precision=2) 15 private double amount; 16 17 @ManyToOne(optional=false, fetch=FetchType.LAZY) 18 @JoinColumn(nullable=false, updatable=false) 19 private Person bidder; 20 21 @ManyToOne(optional=false, fetch=FetchType.LAZY) 22 @JoinColumn(nullable=false, updatable=false) 23 private AuctionItem item; 24 25 public Bid() {} 26 public Bid(long id) {setId(id); } 27 28 public long getId() { 29 return id; 30 } 31 private void setId(long id) { 32 this.id = id; 33 } 34 35 public double getAmount() { 36 return amount; 37 } 38 public void setAmount(double amount) { 39 this.amount = amount; 40 } 41 42 public Person getBidder() { 43 return bidder; 44 } 45 public void setBidder(Person bidder) { 46 this.bidder = bidder; 47 } 48 49 public AuctionItem getItem() { 50 return item; 51 } 52 public void setItem(AuctionItem item) { 53 this.item = item; 54 } 55 56 public String toString() { 57 StringBuilder text = new StringBuilder(); 58 text.append("id=" + id); 59 text.append(", bidder=" + (bidder==null?null:bidder.getUserId())); 60 text.append(", item=" + (item==null ? null : item.getId())); 61 text.append(", $" + amount); 62 return text.toString(); 63 } 64 }