I’m using:
- Hibernate
- MySQL
- jBoss
I have to create an application that allows user to make friendship.
I’m still in design phase, and I would like to have these tables:
- User {_id, name, address}
- Friendship {idUserA, idUserB, date}
For my purpose I should have a mutual relationship from Users. For example 1 is friend of 2 and indirectly 2 is friend of 1.
So in my table I think to have:
Friendship = {1, 2, …}
I’m asking how I can simulate this behaviour. I’ve read his topic: Many-to-many on the same table with additional columns and I’ve followed this instruction generating database tables from entity (property of hibernate). But in this example when I load my Friend A, I’ve a list with Friend B and when I load B I haven’t user A into List.
How I can implement this damn mutual relationship?
As far as I understand this sample the mutuality is not implicit. To have friendship relation from A->B and from B->A you have to either add two entries into your table or you have to implement two sets and return an intersection of the two list: