title: JPA many-to-many update
body: <p>Just another one regarding many to many relationship in JPA. I have the following structure in my database:</p>
  
  <pre><code> ______      ___________      _______
  | user |    | user2item |    | item  |
  |------|    |-----------|    |-------|
  | id   |    | user_id   |    | id    |
  | name |    | item_id   |    | name  |
   ------      -----------     | type  | 
                                -------
  </code></pre>
  
  <p>Now i want to update the assingment from one user to items of a given type. So unfortunately i can't simply do:</p>
  
  <pre><code>user.setItems(newItemList);
  </code></pre>
  
  <p>because it would remove the assignments to items of other types. In plain old SQL i would do:</p>
  
  <pre><code>DELETE FROM user2item WHERE user_id = ? AND item_id IN (SELECT id FROM item WHERE type=?);
  INSERT INTO user2item (user_id, item_id) VALUES(?,?);
  </code></pre>
  
  <p>But as i'm using JPA with QueryDSL plain SQL is no option.</p>