title: Spring JPA intersect two list fields of an entity
body: <p>I have a entity called <code>A</code> which has one property <code>userGroups</code>:</p>
  
  <pre><code>@entity
  Public class A {
  
  @OneToMany
  @JoinTable(name = "a_user_groups", ...)
  private Set&lt;UserGroup&gt; userGroups;
  ...
  }
  </code></pre>
  
  <p>I need to find those <code>A</code> entities which their <code>userGroups</code> has no intersection with given <code>Set&lt;UserGroup&gt; userGroups</code> parameter.</p>
  
  <p>This is my method:</p>
  
  <pre><code>@Query("SELECT a FROM A a WHERE :userGroups intersect a.userGroups is NULL")
  List&lt;A&gt; getAWithNoIntersectionInGroups(@param("userGroups") Set&lt;UserGroup&gt; userGroups)
  </code></pre>
  
  <p>But there is no <code>intersect</code> keyword in jpa. </p>
  
  <p><code>Not In</code> keyword not works here: </p>
  
  <p>Suppose there is an <code>A</code> entity with user groups ids <code>{1,3}</code> and my passed user group ids are <code>{3,4}</code>, Now <code>{1,3}</code> is not in <code>{3,4}</code> and it's true and entity will be selected, but it shouldn't selected, because there is a mutual item <code>{3}</code></p>