有一个客户Customer,里面有一下属性:
@Entity
@Table(name="t_customer")
public class Customer {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
private String cusName;
private String cusTel;
private String cusImgsrc;
@OneToMany(mappedBy="customer",targetEntity=Order.class)
@Cascade(CascadeType.DELETE)
private Set<Order> orders =new HashSet<Order>();
还有一个订单类:
@Entity
@Table(name="t_order")
public class Order {
@Id
@GenericGenerator(name="myuuid",strategy="uuid")
@GeneratedValue(generator="myuuid")
private String id;
private String orderNum;
private String receiverInfo;
@Column(precision=23,scale=2)
private BigDecimal price;
@ManyToOne(targetEntity=Customer.class)
@JoinColumn(name="customer_id")
private Customer customer;
怎么根据客户id去查询到这个客户的所有订单的数量
((Long) this.getHibernateTemplate().find("select count(*) from Order").iterator().next()).intValue();
我写的这个只能查出所有订单.后面不知道怎么写