title: Hibernate - filter child collection by child collection
body: <p>I have the following entities:</p>
  
  <ol>
  <li>Page Group - contains pages.</li>
  <li>Page - below to Page Group, has access roles.</li>
  <li>Role.</li>
  </ol>
  
  <p>I need to query all Page Groups which are allowed to one (or several) selected roles. Queried Page Group can contain not all it's pages. All Pages queried for Page Group must have selected roles.</p>
  
  <p>How can I realise this? Think I must use @Filter but don't know how.</p>
  
  <p>Database scheme is bellow:
  <img src="https://i.stack.imgur.com/j4zLB.png" alt="enter image description here"></p>
  
  <p>Page Group listing:</p>
  
  <pre><code>@Entity
  @Table(name = "PAGE_GROUP")
  public class PageGroup {
  
      @Id
      @Column(name = "pg_id")
      private long id;
      @Column(name = "SOME_FIELD")
      private String field;
      @OneToMany(mappedBy = "group")
      private Set&lt;Page&gt; pages;
  }
  </code></pre>
  
  <p>Page listing:</p>
  
  <pre><code>@Entity
  @Table(name = "page")
  public class Page {
  
      @Id
      @Column(name = "p_id")
      private long id;
      @Column(name = "some_field")
      private String field;
      @JoinColumn(name = "pg_id")
      @ManyToOne
      private PageGroup group;
  
      @ManyToMany
      @JoinTable
      private Set&lt;Role&gt; roles;
  }
  </code></pre>
  
  <p>Role listing</p>
  
  <pre><code>@Entity
  @Table(name = "role")
  public class Role {
  
      @Id
      @Column(name = "r_id")
      private long id;
  
      @Column(name = "some_field")
      private Date field;
      //important: no Page reference
  }
  </code></pre>