[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6089) Give detailed example of ManyToMany with same class at both ends and bidirectional....

Colbert Philippe (JIRA) noreply at atlassian.com
Wed Apr 6 12:04:59 EDT 2011


Give detailed example of ManyToMany with same class at both ends and bidirectional....
--------------------------------------------------------------------------------------

                 Key: HHH-6089
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6089
             Project: Hibernate Core
          Issue Type: Task
          Components: core
    Affects Versions: 3.6.2
         Environment: Windows 7
            Reporter: Colbert Philippe


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.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list