1 package ejava.examples.orm.ejbql.annotated; 2 3 import java.util.ArrayList; 4 import java.util.Collection; 5 import java.util.Date; 6 7 import javax.persistence.*; 8 9 10 @Entity @Table(name="ORMQL_CLERK") 11 public class Clerk { 12 private long id; 13 private String firstName; 14 private String lastName; 15 private Date hireDate; 16 private Date termDate; 17 private Collection<Sale> sales = new ArrayList<Sale>(); 18 19 @Id @GeneratedValue @Column(name="CLERK_ID") 20 public long getId() { 21 return id; 22 } 23 @SuppressWarnings("unused") 24 private void setId(long id) { 25 this.id = id; 26 } 27 @ManyToMany(mappedBy="clerks", fetch=FetchType.LAZY) 28 public Collection<Sale> getSales() { 29 return sales; 30 } 31 public void setSales(Collection<Sale> sales) { 32 this.sales = sales; 33 } 34 35 @Temporal(TemporalType.DATE) 36 public Date getHireDate() { 37 return hireDate; 38 } 39 public void setHireDate(Date hireDate) { 40 this.hireDate = hireDate; 41 } 42 @Temporal(TemporalType.DATE) 43 public Date getTermDate() { 44 return termDate; 45 } 46 public void setTermDate(Date termDate) { 47 this.termDate = termDate; 48 } 49 50 public String getFirstName() { 51 return firstName; 52 } 53 public void setFirstName(String firstName) { 54 this.firstName = firstName; 55 } 56 public String getLastName() { 57 return lastName; 58 } 59 public void setLastName(String lastName) { 60 this.lastName = lastName; 61 } 62 63 public String toString() { 64 StringBuilder text = new StringBuilder(); 65 text.append("id=" + id); 66 text.append(", firstName=" + firstName); 67 text.append(", lastName=" + lastName); 68 text.append(", hireDate=" + hireDate); 69 text.append(", termDate=" + termDate); 70 text.append(", sales(" + sales.size() + ")={"); 71 for(Sale s : sales) { 72 text.append(s.getId() + ", "); 73 } 74 text.append("}"); 75 return text.toString(); 76 } 77 }