I have this object Friendship:
@ManyToOne
private User user1;
@ManyToOne
private User user2;
... and other properties of the friendship
In friendship, there is only one instance / record of this object (not 2), so there can be no problem when John is a friend of Jane, but not vice versa. Records are also normalized, therefore a friendship member with the lowest identifier user1and another member user2, which means that I can prevent duplicate recording with a simple unique restriction.
To get friendly with a specific user, I execute the request with
WHERE user1 = :me OR user2 = :me.
Can this property be matched with @OneToMany Set<Friendship> User?
( Friendshiphas other properties, so it’s not easy @ManyToMany Set<User> friends)
source
share