Hello.
I have an @Entity class, Person, with a @ManyToMany relation with itself. This relation is the friend association. The code of the class is as follows:
@Entity
@Table(name = "PERSON", uniqueConstraints={@UniqueConstraint(columnNames={ "PERSON_NAME"})})
public class Person {
@Id
@GeneratedValue
@Column(name = "PERSON_ID")
private Long id;
@Column(name = "PERSON_NAME")
private String name;
@ManyToMany
@JoinTable(name = "FRIENDS",
joinColumns = @JoinColumn(name = "PERSON_A"),
inverseJoinColumns = @JoinColumn(name = "PERSON_B"))
private Set<Person> friends = new HashSet<Person>();
/*contructors, getters, setters, etc*/
}
The way the class is defined right now allows for the simultaneous existence of <peter, john> and <john, peter> relations when there should only be one (because john and peter are friends implies peter an john are friends). Does the Java Persistence API supply a mechanism to enforce this type of behaviour?
Any help would be apreciated.
Thanks in advance,