-->
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.  [ 4 posts ] 
Author Message
 Post subject: Foreign Key as Discriminator
PostPosted: Tue Sep 30, 2008 10:59 am 
Newbie

Joined: Fri Feb 29, 2008 7:05 am
Posts: 13
Location: New Delhi, India
Hi All,

Can a foreign key act as a discriminator? I have got two entity families A & B. Both A & B follow 'table per class hierarchy'. I need to associate A1 (subclass of A) with B1(subclass of B) & A2 (another persistent subclass of A) with B2(another persistent subclass of B.

Is it possible or I am just thinking too aloud here?

Regards,
Nitin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2008 2:43 pm 
Beginner
Beginner

Joined: Tue Dec 27, 2005 1:13 pm
Posts: 25
Location: Kingston, ON, Canada
---


Last edited by lcbdl on Wed Oct 01, 2008 2:51 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 01, 2008 2:46 pm 
Beginner
Beginner

Joined: Tue Dec 27, 2005 1:13 pm
Posts: 25
Location: Kingston, ON, Canada
If you follow the "table per class" as you said, it should be as below:

1. There are two tables, A and B. A and B should have their discriminator columns, so that class A1 and A2 can extend class A; class B1 and B2 can extend class B

2. To associate A1 with B1; A2 with B2, you can just add a property as the code below:

3.
Code:
public class A1 extends A {
   private B1 b1;
   ......
}

public class A2 extends A {
   private B2 b2;
   ......
}


I don't know why you thought a foreign key act as a discriminator?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2008 1:11 am 
Newbie

Joined: Fri Feb 29, 2008 7:05 am
Posts: 13
Location: New Delhi, India
Hi,

I am following "Table per class hierarchy" i.e. a single table for a class and its subclasses. In my design, there is such a requirement that entities of one family are to be associated with the entities of another family. These families are represented by 2 db tables.

regards,
Nitin


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