AFAIK there is no way you can tell hibernate to do this automatically. But what you can do is
- Either have explicit entries for both sides. ie if 1n 2 are friends then in the many to many link table have two entries (1,2) and (2,1)
- Or in the actual relationship table you have entry only for 1 side but create a view which will be the union of buddies from both sides and use this view as the relationship table in hibernate.
- Or in the relationship table you have entry only for 1 side and use the same table as the linking table, but have two Set properties in the entity - one for left and other for right ; and when you call getFriends() method on the User entity, you merge the two lists and return that.
I will opt for the first one but coz in that case your data model agrees exactly with the relational DB. Remember, in a relational DB a relation is symmetrical only if there are tuples (A,B) and (B,A) existing.