title: Hibernate: @OneToMany - additional condtions? @Filter?
body: <p>In our Database we have a lot of Objects that are <em>shared</em> between Users. For Instance <code>Contacts</code>, <code>Customers</code>, <code>Companies</code>, etc...</p>
  
  <p>There are also a lot of <em>private</em> Objects, that are mapped to one of the <em>shared</em> entity, but should be visible only to the user that created it - for example <em>Notes</em></p>
  
  <p>Our Customer Entity contains a <code>@OneToMany</code> Mapping for <code>Notes</code> and <code>Contacts</code></p>
  
  <pre><code>@Entity
  public Class Customer{
  
      @OneToMany
      Set&lt;Contact&gt; contacts;
  
      @OneToMany
      Set&lt;Note&gt; notes;
  }
  </code></pre>
  
  <p>Currently I would need to load thausands of notes, just to figure out : The current user has no note for that customer...</p>
  
  <p>So i thought about something to "filter" the collection before loading it - and indeed, Hibernate does support the <code>@Filter</code> annotation for that purpose (it seems), so, I would need to apply the following annotation as well: </p>
  
  <pre><code>    @OneToMany
      @Filter(name="userIdFilter", condition=" :userIdFromSession = userId")
      Set&lt;Note&gt; notes;
  </code></pre>
  
  <p>But on everything else, the documentation leaves some questions. Every example now continues with showing how to set the filters value (<code>:userIdFromSession</code>), when using <code>session.createQuery()</code></p>
  
  <pre><code>Session session = ...;
  session.enableFilter("userIdFilter").setParameter("userIdFromSession", session.getUser().getId());
  List results = session.createQuery(...)
  </code></pre>
  
  <p>But <strong>how</strong> can I enable the filter (and set the targetvalue) when using the Entity-Manager along with <code>em.find()</code>, sot the target value is "applied" for every Filter condition in the Object-Tree?</p>