-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: define many to many problem
PostPosted: Wed Feb 03, 2010 12:24 pm 
Newbie

Joined: Mon Feb 01, 2010 7:51 pm
Posts: 4
Hi,

Lets say I have a table in my database that contains some person info.

I have another table that represent friend connection between two persons.
the table have two columns: first_person_id and second_person_id (friend connection, right? one person is friend of another).

I want to create person object in my domain, that have field for friends.

The problem is that the person_id can be in first_person_id or second_person_id
so I dont know how to map this relation well.

I thought about using view to flat the friends relationship, but it create new problems, when i want to add new items to the friends table.

any ideas how can I map this relationship?


Top
 Profile  
 
 Post subject: Re: define many to many problem
PostPosted: Wed Feb 03, 2010 4:19 pm 
Beginner
Beginner

Joined: Wed Jul 05, 2006 12:45 pm
Posts: 21
I would represent a "friendship" relationship between two Persons as TWO separate rows in the database:

subject_id | friend_id
-----------------------------------
person1 | person2
-----------------------------------
person2 | person1

I think this is semantically more correct, and would work well with NH many-to-many facilities.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.