I have two objects:
@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; ...
Now in my JPQL I want to return these customers with CustomerOrder.cost> 1000. For example, there are three clients A, B and C. A has two orders with a value of = 1000 and 2000, respectively. B has three orders with cost = 2000-3000 and 500, respectively. C has one order with cost = 500. Now I want to get three customers: A returns orders only with cost = 2000; B returns orders from 2000 and 3000; C returns an empty collection of orders.
But the complete collection will always be returned:
select c from Customer c, in(c.customerOrders) o where o.cost>1000
How can I do this in JPQL or in Hibernate in particular?
hibernate jpa jpql
jscoot
source share