我有两个实体:
@Entity
public class Customer implements java.io.Serializable {
...
@OneToMany(fetch=FetchType.EAGER, mappedBy="customer")
private Set<CustomerOrder> customerOrders;
...
@Entity
public class CustomerOrder implements java.io.Serializable {
....
private double cost;
@ManyToOne
@JoinColumn(name="CUST_ID")
public Customer customer;
...
现在在我的JPQL中,我想返回那些CustomerOrder.cost>1000的客户。例如,有三个客户A、B和C。A有两个订单,成本分别为1000和2000。B有三个订单,成本分别为2000、3000和500。C有一个订单,成本为500。现在我想获取这三个客户:A仅返回成本为2000的订单;B返回成本为2000和3000的订单;C返回一个空的订单集合。
但是以下代码将始终返回完整的集合:
select c from Customer c, in(c.customerOrders) o where o.cost>1000
我该如何在JPQL或特定的Hibernate中实现这个功能?