title: Querydsl Many2many join
body: <p>I'm rather new to QueryDSL so this may be an easy one. I have the following structure in my database:</p>
  
  <pre><code> ______      ___________      _______
  | user |    | user2item |    | item  |
  |------|    |-----------|    |-------|
  | id   |    | user_id   |    | id    |
  | name |    | item_id   |    | name  |
   ------      -----------      -------
  </code></pre>
  
  <p>Now i want to get all users that have at least one item in common with a given user. So i tried:</p>
  
  <pre><code>JPASubQuery subQuery = new JPASubQuery().from(user, item).join(user.items, item).where(user.id.eq(myUserId));
  return new JPAQuery(entityManager).from(user).where(user.items.in(subQuery.list(item))).list(user);
  </code></pre>
  
  <p>But this gives me a problem in the 'in' clause because the subquery.list() does not return a List&lt;Item&gt; but a ListSubQuery&lt;Item&gt;. Any help would be really appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks Timo, your suggestion works - but unfortunately if you have more than one subqueries of this kind the resulting statement is much slower than:</p>
  
  <pre><code>User myUser = repository.findOne(myUserId);
  
  return new JPAQuery(entityManager)
             .from(user)
             .join(user.items, item)
             .where(item.in(myUser.getItems()))
             .list(user);
  </code></pre>