ManyToMany Relation does not create the primary key
Posted
by Javi
on Stack Overflow
See other posts from Stack Overflow
or by Javi
Published on 2010-04-08T08:11:38Z
Indexed on
2010/04/08
9:03 UTC
Read the original article
Hit count: 394
Hello,
I have a ManyToMany relationship between two classes: ClassA and ClassB, but when the table for this relationship (table called objectA_objectB) there is no primary key on it.
In my ClassA I have the following:
@ManyToMany(fetch=FetchType.LAZY)
@OrderBy(value="name")
@JoinTable(name="objectA_objectB",
joinColumns=
@JoinColumn(name="idObjectA", referencedColumnName="id"),
inverseJoinColumns=
@JoinColumn(name="idObjectB", referencedColumnName="id")
)
private List<ClassB> objectsB;
and in my ClassB I have the reversed relation
@ManyToMany
List<ClassA> objectsA;
I just want to make a primary key of both id's but I need to change the name of the columns as I do. Why is the PK missing? How can I define it?
I use JPA 2.0 Hibernate implementation, if this helps.
Thanks.
© Stack Overflow or respective owner