Im facing an issue with The following:
public class Person {
private long id;
private String name;
private List<Relation> relations;
....
}
public class Relation {
private Person person;
private Person relatedWith;
private String relationType;
}
The goal is to annotate these classes with JPA so any given person can have a relation with any other person.(thus manytomany)
The relation table should have a combined primary key consisting of the person.id and the relatedWith.id.
How can i do this?
Thanks for your help!
Richard
You should not use combined primary key, use a generated one (e.g. sequence or autoincrement column for Relation table) and then you’ll have two foreign keys back to the Person table.