title: Hibernate: Select entities where collection contains all of the specified valus
body: <p>I need assistance with a tricky hibernate query problem. I have the following entities:</p>
  
  <pre><code>public class Book {
     private String bookId;
     private String author;
     private String isbn;
     private Set&lt;Tag&gt; tags;
     // getters, setters etc.
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class Tag  {
     private String tagId;
     private String tagName;
    // getters, setters, etc.
  }
  </code></pre>
  
  <p>There is a many-to-many association between the two that is represented by a join table books_tags_mn with the columns book_id and tag_id.</p>
  
  <p>What I like to do is the following: I want to create a hibernate query/criteria query that returns all book that have <strong>all</strong> of a certain set of tags. What does work is to select all books that have <strong>any</strong> of a set of tags.</p>
  
  <p>I've been messing around with the criteria API but did not truly understand it. So what I am trying to do (in pseudo HQL)</p>
  
  <pre><code>from Book book where book.tags containsAll(:tags)
  </code></pre>
  
  <p>Any help on this would be highly appreciated, so thank you very much in advance.</p>