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.  [ 6 posts ] 
Author Message
 Post subject: Mapping a table to itself.
PostPosted: Fri Nov 02, 2007 3:30 pm 
Newbie

Joined: Mon Jun 18, 2007 2:08 pm
Posts: 10
Folks,

I have situation in which a row might have a relationship other rows. I am sure someone has had this scenario - An example would be better to clarify:


Lets say we have a club object. A club has person as member and a person has family members that are also automatically part of the club.

Club
|
+- List of person (club members)


Person
|
+ List of person (family members)

How could I annotate that scenario ?

Class Club
{
List<Person> member;

@What is the annotation ?
g/set(){}
}

Class Person
{

List<Person> familyMembers;

g/set(List<Person> familyMembers){}
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 3:33 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
how about using a third table to store the relationship between person and person?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 3:41 pm 
Newbie

Joined: Mon Jun 18, 2007 2:08 pm
Posts: 10
The person table already contain a column that is the value of the "parent" person on the relationship.

Person
+--------------------------------+
| id | pid | name <etc> |
+--------------------------------+
| 1 | 0 | Daddy |
+--------------------------------+
| 2 | 1 | Son |
+--------------------------------+
| 3 | 1 | daughter |
+--------------------------------+


Thanks for the reply, though.


harringf


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 3:45 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
It looks like a many-to-one relationship but I kinda feel creepy with this design. Consider using a relationship table if you have the option.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 3:48 pm 
Newbie

Joined: Mon Jun 18, 2007 2:08 pm
Posts: 10
Fazard,

Thanks for the quick reply. Unfortunately, that is not an option.

harringf


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 9:14 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
I'm completely confused by this. Harringf, what is the issue you are encountering? I can't think of an issue here. What is your question? Could you explain it better so maybe I can provide better feedback? You can map a given type to itself, that should not be an issue.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.