title: JPA Where Exists/Join
body: <p>i have a problem with a jpa query:</p>
  
  <pre><code>SELECT DISTINCT p FROM Product p INNER JOIN p.shopCategories sc WHERE EXISTS (SELECT DISTINCT sc2 FROM Customer c INNER JOIN c.shopCategories as sc2 WHERE c.customerId=7)
  </code></pre>
  
  <p>The result should be only pages which have a shop categories where the customer has booked that shop category.</p>
  
  <p>Product &lt;-> ShopCategory &lt;-> Customer</p>
  
  <p>But the result is a list with all products for which any ShopCategory exists.</p>
  
  <p>Any ideas how to improve the query?</p>