-->
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.  [ 1 post ] 
Author Message
 Post subject: Inheritance - Best practice?
PostPosted: Thu Feb 17, 2011 3:16 am 
Beginner
Beginner

Joined: Sat Dec 01, 2007 4:34 pm
Posts: 20
In my app I have a one-to-one relationship between the two tables below, Category and Chapter.

Chapter contains a bit additional information like which book it's realted to and chapter order.

My question is: what is the best way to map this in Hibernate and what is the best way structure the tables?

In the first table structure there will be a one-to-one relationship between CategoryId and ChapterId, and they will share the same primary key.
Code:
#1
Category                      Chapter
CategoryId (PK)               ChapterId (PK, FK)
Title                         ChapterOrder
CategoryLevel                 BookId
CategoryType


In the second table structure CategoryId is the foreign key in table Chapter. So there is actually a one-to-many relationship between the tables. But if you make foreign key categoryId unique it's basically on-to-one. I hvae read in a Hibernate book that shared primary keys are not very common.

What is the best inheritance strategy? Joined? Or is it better to use one-to-one?

Code:
#2
Category                      Chapter
CategoryId (PK)               ChapterId (PK)
Title                         ChapterOrder
CategoryLevel                 BookId
CategoryType                  CategoryId (FK, UNIQUE)


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

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.