Rejected
Details
Assignee
UnassignedUnassignedReporter
Colbert PhilippeColbert PhilippeComponents
Priority
Major
Details
Details
Assignee
Unassigned
UnassignedReporter
Colbert Philippe
Colbert PhilippeComponents
Priority
Created April 6, 2011 at 6:04 PM
Updated October 30, 2013 at 9:47 AM
Resolved October 30, 2013 at 9:47 AM
I thought I knew Hibernate well but I got stuck with this issue. I am trying to implement a friend relationship between instances of Person class. Naturally, any Person can have any number of friends, which are other instances of Person.
The complication comes from the fact that friend relationship is perfectly symmetric and bi-directional in my application. That is if Person(1) is friend with Person(2), then Person(2) is friend with Person(1) also.
I want to implement this friend relationship in Hibernate using an intermediate class that will hold certain attributes describing further the friendship relationship like date when friendship started, some text note about the friendship,....etc.
Implementing this using Hibernate causes some challenges and even difficulties because I am not sure about how Hibernate handles class IDs internally.
Can you provide an example of Hibernate config file that implements the Many-To-Many on the same class at both ends and with intermediate data class? There should be no order in the relationship (i.e. the relationship is perfectly symmetric).
I suspect that the solution to this issue is to code a composite id class where there is no order between the two ids from Person class. However, I am not sure whether that is sufficient for Hibernate.