1 package org.hibernate.ce.auction.model; 2 3 import javax.persistence.*; 4 import java.io.Serializable ; 5 import java.util.Date ; 6 7 8 15 @Entity(access = AccessType.FIELD) 16 @Table(name = "BID") 17 @org.hibernate.annotations.Entity(mutable = false) 18 public class Bid implements Serializable , Comparable { 19 20 @Id(generate = GeneratorType.AUTO) 21 @Column(name = "CAT_ID") 22 private Long id = null; 23 24 @org.hibernate.annotations.Type(type = "monetary_amount_usd") 25 @org.hibernate.annotations.Columns( columns = { 26 @Column( name="AMOUNT"), 27 @Column( name="AMOUNT_CURRENCY", length = 2) 28 } 29 ) 30 private MonetaryAmount amount; 31 32 @ManyToOne() 33 @JoinColumn(name = "ITEM_ID", nullable = false) 34 private Item item; 35 36 @ManyToOne() 37 @JoinColumn(name = "BIDDER_ID", nullable = false) 38 private User bidder; 39 40 @Column( nullable = false, updatable = false) 41 private Date created = new Date (); 42 43 46 Bid() {} 47 48 55 56 public Bid(MonetaryAmount amount, Item item, User bidder) { 57 this.amount = amount; 58 this.item = item; 59 this.bidder = bidder; 60 } 61 62 64 public Long getId() { return id; } 65 66 public MonetaryAmount getAmount() { return amount; } 67 public Item getItem() { return item; } 68 public User getBidder() { return bidder; } 69 public Date getCreated() { return created; } 70 71 73 public boolean equals(Object o) { 74 if (this == o) return true; 75 if (!(o instanceof Bid)) return false; 76 77 final Bid bid = (Bid) o; 78 79 if (!amount.equals(bid.amount)) return false; 80 if (!created.equals(bid.created)) return false; 81 82 return true; 83 } 84 85 public int hashCode() { 86 int result; 87 result = amount.hashCode(); 88 result = 29 * result + created.hashCode(); 89 return result; 90 } 91 92 public String toString() { 93 return "Bid ('" + getId() + "'), " + 94 "Created: '" + getCreated() + "' " + 95 "Amount: '" + getAmount() + "'"; 96 } 97 98 public int compareTo(Object o) { 99 if (o instanceof Bid) { 100 return this.getCreated().compareTo( ((Bid)o).getCreated() ); 101 } 102 return 0; 103 } 104 105 107 108 } | Popular Tags |