Is there a way to map a bidirectional symmetric relationship in Hibernate / JPA?

129 Views Asked by At

I would like to implement a User-Friend relationship in Hibernate/JPA, something like:

 class User {
    Set<User> friends;
 }

Let's say that user A and user B are friends. If user A unfriends user B, list of friends of User B should not contain user A anymore.

Is there any clean way to model this kind of relation in Hibernate/JPA (and, of course, in the underlying DB tables)?

0

There are 0 best solutions below