title: JPA @JoinTable with extra join conditions
body: <p>I have spent couple of hours searching around and did not found anything similar to my case.</p>
  
  <p>Let's assume following many-to-many data model:</p>
  
  <pre>
  Contract (any business entity)
  - contract_id
  - other fields
  
  Party (another business entity)
  - party_id
  - other fields
  
  Contract_Party (relations between first two 
  with additional role indicator, e.g. owner, signer, seller, etc)
  - contract_id
  - party_id
  - role
  </pre>
  
  <p>Now let's assume I want to map <strong>all</strong> contracts related to party (uni-directional). It can be done using following annotations in <code>Party</code> entity class:</p>
  
  <pre><code>@OneToMany
  @JoinTable(
    name="Contract_Party", 
    joinColumns = {@JoinColumn(name="party_id", referencedColumnName="party_id")},
    inverseJoinColumns = {@JoinColumn(name="contract_id", referencedColumnName="contract_id")}
  }
  private List&lt;Contract&gt; contracts;
  </code></pre>
  
  <p>That is fine.</p>
  
  <p>But what I'm looking for is how to map contracts with <strong>particular role</strong>?</p>
  
  <pre><code>@OneToMany
  @??? ( "ROLE = 'SIGNER' ")
  private List&lt;Contract&gt; signedContracts;
  </code></pre>
  
  <p>Technically I'm looking for a way to add <strong>extra condition</strong> into JOIN statement.</p>
  
  <p>So far found following ideas in similar topics:</p>
  
  <ul>
  <li>map join table as separate entity, and perform filtering by role using custom queries;</li>
  <li>Hibernate has @JoinFormula annotation, but no way to apply it inside @JoinTable;</li>
  <li>Hibernate also has @Where annotation, but it adds condition for Contract table not for join table;</li>
  <li>use @MapKeyColumn and return Map instead of List, but I can have multiple contracts per one role;</li>
  <li>create a view on DB side (this one works indeed :)</li>
  </ul>
  
  <p>Thanks!</p>