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