title: How to add a separate Primary Key to a Join Table in Hibernate
body: <p>I have a question about Hibernate ManyToMany mappings. I have two classes A and B and the mapping between them is a ManyToMany mapping resolved by Hibernate:</p>
  
  <pre><code>@Entity
  @Table(name="A")
  public class A {
  
      @Id
      @GeneratedValue
      private Long id;
  
      @ManyToMany
      @JoinTable(name="C", joinColumns=@JoinColumn(name="a_id"), inverseJoinColumns=@JoinColumn(name="b_id"))
      private Set bs;
  }
  
  @Entity
  @Table(name="B")
  public class B {
  
      @Id
      @GeneratedValue
      private Long id;
  
      @ManyToMany(mappedBy="bs")
      private Set bs;
  }
  </code></pre>
  
  <p>As you can see, the Join Table I use is C. The foreign keys to A and B are "a_id" and "b_id". My understanding is, that Hibernate creates a composed Primary Key with a_id and b_id for table C. </p>
  
  <p>I don't want to have an entity C in my model. But instead of a composed primary key on table C, I would like to have a generated ID and a unique constraint on the fields a_id and b_id. </p>
  
  <p>Is it possible to tell Hibernate to use a separate primary key? Without adding an entity C? </p>
  
  <p>I would appreciate any help.</p>
  
  <p>Thanks a lot! </p>