1 package ejava.examples.orm.ejbql.annotated; 2 3 import java.math.BigDecimal; 4 import java.util.ArrayList; 5 import java.util.Collection; 6 import java.util.Date; 7 8 import javax.persistence.*; 9 10 @Entity 11 @Table(name="ORMQL_SALE") 12 public class Sale { 13 private long id; 14 private Date date; 15 private BigDecimal amount = new BigDecimal(0); 16 private long buyerId; 17 private Store store; 18 private Collection<Clerk> clerks = new ArrayList<Clerk>(); 19 20 @Id @GeneratedValue @Column(name="SALE_ID") 21 public long getId() { 22 return id; 23 } 24 public void setId(long id) { 25 this.id = id; 26 } 27 @ManyToMany(fetch=FetchType.LAZY) 28 @JoinTable(name="ORMQL_SALE_CLERK_LINK", 29 joinColumns={@JoinColumn(name="SALE_ID")}, 30 inverseJoinColumns={@JoinColumn(name="CLERK_ID")} 31 ) 32 public Collection<Clerk> getClerks() { 33 return clerks; 34 } 35 public void setClerks(Collection<Clerk> clerks) { 36 this.clerks = clerks; 37 } 38 @ManyToOne(optional=false) 39 @JoinColumn(name="SALE_STORE") 40 public Store getStore() { 41 return store; 42 } 43 public void setStore(Store store) { 44 this.store = store; 45 } 46 47 @Column(precision=5, scale=2) 48 public BigDecimal getAmount() { 49 return amount; 50 } 51 public void setAmount(BigDecimal amount) { 52 this.amount = amount; 53 } 54 @Column(nullable=false) 55 public long getBuyerId() { 56 return buyerId; 57 } 58 public void setBuyerId(long buyerId) { 59 this.buyerId = buyerId; 60 } 61 62 @Temporal(TemporalType.DATE) 63 public Date getDate() { 64 return date; 65 } 66 public void setDate(Date date) { 67 this.date = date; 68 } 69 70 public String toString() { 71 StringBuilder text = new StringBuilder(); 72 text.append("id=" + id); 73 text.append(", date=" + date); 74 text.append(", amount=" + amount); 75 text.append(", buyer=" + buyerId); 76 text.append(", clerks(" + clerks.size() + ")={"); 77 for(Clerk c : clerks) { 78 text.append(c.getId() + ", "); 79 } 80 text.append("}"); 81 return text.toString(); 82 } 83 }