I have a question about Hibernate ManyToMany mappings. I have two classes A and B, and the mapping between them is the ManyToMany mapping allowed by Hibernate:
@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; }
As you can see, the Join table that I use is C. The foreign keys to A and B are "a_id" and "b_id". I understand that Hibernate creates a compiled primary key with a_id and b_id for table C.
I do not want to have a C entity in my model. But instead of the compiled primary key in table C, I would like to have a generated identifier and a unique constraint for the a_id and b_id fields.
Can I tell Hibernate to use a separate primary key? Without adding entity C?
I would be grateful for any help.
Thank you so much!
java orm hibernate jpa
Bhulliger
source share