title: JPA : Many to Many query help needed
body: <p>I have four entities that are involved in a query that I'm having a little trouble with.  The relationship is as follows : <code>Exchange----*Contract*----*Combo----*Trade</code> and the (simplified) entities are as follows:</p>
  
  <pre><code>@Entity
  public class Exchange implements Serializable {
      @Id(name="EXCHANGE_ID")
      private long exchangeId;
  
      @Column
      private String exchangeShortName;
  }
  
  
  @Entity
  public class Contract implements Serializable { 
          @Id
          private long contractId;
  
          @Column
          private String contractName;
  
          @ManyToOne
          @JoinColumn(name="EXCHANGE_ID")
          private Exchange exchange;
  
          @ManyToMany
          @JoinTable(name="CONTRACT_COMBO",
                          joinColumns = { @JoinColumn(name="CONTRACT_ID") },
                          inverseJoinColumns = {@JoinColumn(name="COMBO_ID")})
          private Set&lt;Combo&gt; combos;
  
          @Column(name = "ACTIVE_FLAG")
          private String activeFlag;
  }
  
  @Entity
  public class Combo implements Serializable {
  
          @Id
          @Column(name="COMBO_ID")
          private Integer id;
  
          @ManyToMany
          @JoinTable(name="CONTRACT_COMBO",
                          joinColumns = { @JoinColumn(name="COMBO_ID") },
                          inverseJoinColumns = {@JoinColumn(name="CONTRACT_ID")})
          private Set&lt;Contract&gt; legs;
  
          @OneToMany(mappedBy = "combo")
          private Set&lt;Trade&gt; trades;    
  }
  
  @Entity
  public class Trade implements Serializable {
          @Id
          @Column(name="TRADE_ID")
          private long tradeId;
  
          @Column(name="REFERENCE")
          private String reference;
  
          @ManyToOne
          @JoinColumn(name="COMBO_ID")
          private Combo combo;
  }
  </code></pre>
  
  <p>I want to get a list of all trades for a particular exchange which I can't quite get to work with <code>MEMBER OF</code>.  Any help would be appreciated.</p>