title: Conditional @OnetoMany relationship in Ebean
body: <p>I have a <code>parent</code> entity which has a <code>OneToMany</code> relationship with a <code>child</code> entity.</p>
  
  <p>I'd like to define a conditional relationship between these where <code>child</code> has an <code>attribute</code> column field with a value of 3. <code>attribute</code> is an integer column in <code>child</code> table like so in the model:</p>
  
  <pre><code>@Constraints.Required
  @NotNull
  protected Integer attribute;
  </code></pre>
  
  <p>Here is what I tried in the <code>parent</code> entity class:</p>
  
  <pre><code>@OneToMany(mappedBy = "parent")
  @Where(clause = "attribute = 3")
  List&lt;Child&gt; specificChildren;
  </code></pre>
  
  <p>However the generated query ignores the where clause I made, and gives me all children relating to that parent, not just the ones with <code>attribute = 3</code>. Changing the <code>clause</code> to <code>${ta}.attribute = 3</code> was also unsuccessful.</p>
  
  <p>Here is the SQL generated <code>query.getGeneratedSql()</code>:</p>
  
  <pre><code>select distinct on (t1.attribute, t0.id) t0.id, t1.attribute
  from parent t0
  left join child t1 on t1.parent_id = t0.id
  order by t1.someotherattribute
  </code></pre>
  
  <p>The <code>@Where</code> attribute is being ignored completely, as no matter what I do with it, the generated SQL is not affected.</p>
  
  <p>There is a <code>io.ebean.annotation.Where</code> class, so it seems like it should be able to work, but I haven't found any Ebean specific documentation on it (Ebean's docs do seem to be somewhat lacking). Most information I find about the <code>@Where</code> annotation relates to Hibernate. I did find the source code for it <a href="https://github.com/ebean-orm/ebean-annotation/blob/master/src/main/java/io/ebean/annotation/Where.java" rel="nofollow noreferrer">here</a> though.</p>
  
  <p>Is this supported in this way? Or is there another method this could be accomplished?</p>
  
  <p>I'm currently using PostgreSQL 10.4, Ebean 10.4.4, Play 2.6.7, using Play's Ebean plugin 4.0.6. I tried updating to Play's Ebean 4.1.3 with no success. Not sure if the versions I am using are to blame or not.</p>
  
  <p>More information found in a Google group <a href="https://groups.google.com/forum/#!topic/ebean/N0j2KhIIGR4" rel="nofollow noreferrer">here</a>.</p>