title: How to filter collection in JPA/JPQL?
body: <p>I have two entities:</p>
  
  <pre><code>@Entity
  public class Customer  implements java.io.Serializable {
  ...
      @OneToMany(fetch=FetchType.EAGER, mappedBy="customer")
      private Set&lt;CustomerOrder&gt; customerOrders;
  ...
  
  
  @Entity
  public class CustomerOrder  implements java.io.Serializable {
  ....        
  
      private double cost;
  
      @ManyToOne
      @JoinColumn(name="CUST_ID")
      public Customer customer;
  ...
  </code></pre>
  
  <p>Now in my JPQL, I want to return those customers with their CustomerOrder.cost>1000. For example, there are three customers A, B and C. A has two orders with cost=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 the three customers: A returns the orders with cost=2000 only; B returns the orders with 2000 and 3000; C returns an empty orders collection. </p>
  
  <p>But the following will always return the full collection:</p>
  
  <pre><code>select c from Customer c, in(c.customerOrders) o where o.cost&gt;1000
  </code></pre>
  
  <p>How can I do that in JPQL or in Hibernate in particular?</p>