title: JPA ManyToOne with composite key
body: <p>I have this model mapping for a <strong>Brand</strong> entity:</p>
  
  <pre><code>@Entity
  public class Brand implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @EmbeddedId
      private BrandPk id;
  
  //...
  }
  </code></pre>
  
  <p>The composite key is:</p>
  
  <pre><code>@Embeddable
  public class BrandPk implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      private int id1;
  
      private int id2;
  //...
  }
  </code></pre>
  
  <p>Now I want to join a <strong>Product</strong> entity (one brand, many products):</p>
  
  <p>I will have:</p>
  
  <pre><code>@Entity
  public class Product implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
  
  @ManyToOne
  // ???
  private Brand brand;
  
  //...
  }
  </code></pre>
  
  <p>What will I need to correctly join my tables-entities?</p>
  
  <p><em>table_brands</em> has a PK composing two fields: id1 and id2
  <em>table_products</em> has a PK with an id, and a field <strong>id_brand</strong> refering just to id1.</p>
  
  <p><strong>id2 is not used anymore and not important at all!</strong> </p>
  
  <p>This mapping is for a legacy DB that unfortunately I cannot change, so I need to join "ignoring" id2. 
  How can I?</p>