title: JPA: join table syntax
body: <p>Given the following entity (some columns omitted from this long definition for brevity):</p>
  
  <pre><code>@Table(name = "Products")
  public class Products implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @Basic(optional = false)
      @Column(name = "SKU")
      private String sku;
      @Basic(optional = false)
      @Column(name = "ProductName")
      private String productName;
  
      private boolean allowPreOrder;
      @ManyToMany(mappedBy = "productsCollection")
      private Collection&lt;Categories&gt; categoriesCollection;
      @JoinTable(name = "Products_CrossSell", joinColumns = {
          @JoinColumn(name = "SKU", referencedColumnName = "SKU")}, inverseJoinColumns = {
          @JoinColumn(name = "CrossSKU", referencedColumnName = "SKU")})
      @ManyToMany
      private Collection&lt;Products&gt; productsCollection;
      @ManyToMany(mappedBy = "productsCollection")
      private Collection&lt;Products&gt; productsCollection1;
      @JoinTable(name = "Products_Related", joinColumns = {
          @JoinColumn(name = "SKU", referencedColumnName = "SKU")}, inverseJoinColumns = {
          @JoinColumn(name = "RelatedSKU", referencedColumnName = "SKU")})
      @ManyToMany
      private Collection&lt;Products&gt; productsCollection2;
      @ManyToMany(mappedBy = "productsCollection2")
      private Collection&lt;Products&gt; productsCollection3;
  </code></pre>
  
  <p>How do I get the set of related products for a given product SKU?   </p>
  
  <p>The products_related table looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Vb6sV.jpg" alt="alt text"></p>
  
  <p>I know how to get the answer using SQL but I'm new to JPA so I haven't quite grokked the API and query syntax yet.</p>