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)