title: play framework 2.2 : How to define an ebean ManyToMany query
body: <p>I am trying to implement the yabe tutorial from play 1.0 in play 2.0</p>
  
  <p>Currently I am stuck at the tagging functionality: <a href="http://www.playframework.com/documentation/1.2.3/guide6" rel="nofollow">http://www.playframework.com/documentation/1.2.3/guide6</a></p>
  
  <p>Essentially the problem is this:</p>
  
  <p>I have a Post class, each Post object can have multiple number of tags associated with that class:</p>
  
  <pre><code>@ManyToMany(cascade=CascadeType.PERSIST)
  public Set&lt;Tag&gt; tags;
  </code></pre>
  
  <p>I want to write a function which, given an array of tags, will return a list of Posts, if and only if all tags are present in the Post objects.</p>
  
  <p>The unit tests are as follows:</p>
  
  <pre><code>    @Test
  public void testTags() {
      // Create a new user and save it
      SuperUser.setInstance("bob@gmail.com", "secret", "Bob").save();
  
      SuperUser bob = SuperUser.getInstance();
  
      // Create a new post
      Post bobPost = new Post(bob, "Hello world","My first post");
      bobPost.save();
  
      Post anotherBobPost = new Post(bob, "Hello world", "Hop");
      anotherBobPost.save();
  
      // Well
      assertEquals(0, Post.findTaggedWith("Red").size());
  
      // Tag it now
      bobPost.tagItWith("Red").tagItWith("Blue").save();
      anotherBobPost.tagItWith("Red").tagItWith("Green").save();
  
      // Check
      assertEquals(2, Post.findTaggedWith("Red").size());
      assertEquals(1, Post.findTaggedWith("Blue").size());
      assertEquals(1, Post.findTaggedWith("Green").size());
  
      // Checks for multiple tag params
      assertEquals(1, Post.findTaggedWith("Red", "Blue").size()); //Fail -  Actual: 0
      assertEquals(1, Post.findTaggedWith("Red", "Green").size());
      assertEquals(0, Post.findTaggedWith("Red", "Green", "Blue").size());
      assertEquals(0, Post.findTaggedWith("Green", "Blue").size());
  
      SuperUser.removeSuperUser();
  
  }
  </code></pre>
  
  <p>My current implementation is as follows:</p>
  
  <pre><code>    public static List&lt;Post&gt; findTaggedWith(String... tags) {
  
      ExpressionList&lt;Post&gt; expAcc = Post.find.fetch("tags").where().conjunction();
  
      for( String tag : tags){
  
          expAcc = expAcc.eq("tags.name", tag);
  
      }
  
      return expAcc.endJunction().findList();
  }
  </code></pre>
  
  <p>I have no idea what to do next, as I am brute forcing this and getting nowhere :(</p>
  
  <p>Thanks!</p>