-->
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: Child Table with no primary key
PostPosted: Wed Mar 21, 2007 3:03 pm 
Newbie

Joined: Thu Feb 15, 2007 12:48 pm
Posts: 11
Hi,
Is it possible to have a mapping for a table with no primary key but just a foreign key. In my case, I have a Parent table and a Child table. The child tables has a foreign key to the parent table.

Parent:
ID - PK
Name - char

Child:
PARENT_ID - FK
Name - char
Value - char

Can someone tell me if it is possible to build a mapping for this kind of relationship?

Thanks,
Javid
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 3:38 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
I hope it isn't.

Database Relations depend on Primary Keys and Foreign keys. It isn't necessary that the PK for the child table be used for anything except differentiating one record from the next (as you could easily extract children according to who their parents were), but you need a PK. That's just database design.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 6:49 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
technically i agree with gortok. that data model for the child table insinuates that child is a subclass of parent. in geneology that could indeed be true as a child has children and their children have children, etc. in your app, it may or may not be true.

if you cannot change your data model, then you might be able to change your domain model and model that parent/child relationship as a subclass or even by using the composite pattern (i don't know what the parent/child objects really are). i saw an example of the composite pattern a while ago in the hibernate documentation:

http://www.hibernate.org/86.html

if you chose to subclass child of parent then the mapping becomes straightforward with parent and child sharing the same identifier.

hth,

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 21, 2007 9:35 pm 
Newbie

Joined: Thu Feb 15, 2007 12:48 pm
Posts: 11
Thank you all for your response. Since, we are almost nearing deployment I just added an identity column to the table and got it to work.

Thanks again,
Javid


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.