I have 2 java classes, Relation
and Person
, which both are present in my database.
Person:
@Entity
@Table(name = \"persons\
You can use @FilterDef
and @Filter
annotations.
Some of the options that you could utilize:
Relation
entity.This and this answer could also be helpful.
Also, you can always use two separate associations for slaves and masters:
public class Person {
@OneToMany
@JoinColumn(name = "slave_id"),
private List<Relation> slaves;
@OneToMany
@JoinColumn(name = "master_id"),
private List<Relation> masters;
public List<Relation> getRelations() {
List<Relation> result = new ArrayList<>(slaves);
result.addAll(masters);
return result;
}
}
However, keep in mind that joining all of them in a single query requires full Cartesian product between masters and slaves.