1 package ejava.examples.orm.ejbql.annotated; 2 3 import java.util.ArrayList; 4 import java.util.Collection; 5 6 import javax.persistence.*; 7 8 @Entity @Table(name="ORMQL_STORE") 9 public class Store { 10 private long id; 11 private String name; 12 private Collection<Sale> sales = new ArrayList<Sale>(); 13 14 @Id @GeneratedValue @Column(name="STORE_ID") 15 public long getId() { 16 return id; 17 } 18 @SuppressWarnings("unused") 19 private void setId(long id) { 20 this.id = id; 21 } 22 23 @OneToMany(mappedBy="store", 24 cascade={CascadeType.REMOVE}, 25 fetch=FetchType.LAZY) 26 public Collection<Sale> getSales() { 27 return sales; 28 } 29 public void setSales(Collection<Sale> sales) { 30 this.sales = sales; 31 } 32 33 public String getName() { 34 return name; 35 } 36 public void setName(String name) { 37 this.name = name; 38 } 39 40 public String toString() { 41 StringBuilder text = new StringBuilder(); 42 text.append("id=" + id); 43 text.append(", name=" + name); 44 text.append(", sales(" + sales.size() + ")={"); 45 for(Sale s : sales) { 46 text.append(s.getId() + ", "); 47 } 48 text.append("}"); 49 return text.toString(); 50 } 51 }