Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Foreign Keys

 
Mag Wells
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following tables

Publisher, Book and author

book has a foreign key pointing to the author_id and a bookcategory_id pointing to the book category.
publisher has a foreign key pointing to the book_id
book has a primary key id

Now when I try to reverse engineer using hibernate tools it gives me this error -



If i starting putting the foreign keys in every table to satisfy the above constraint, it makes no sense to have a DB !!
 
Mark Dahlerup
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What are the PK/FK columns of each table
Where is the bookcategory_id ? (ie which table)
Is there a BOOKS table and/or a BOOK table as the error message is for 'books' ?
If the PK on a table has multiple columns to uniquely identify a row then FKs back to the parent must also have the same information so the correct row can uniquely be identified.
The PK of books [id,bookcategory_id,author_id]) seems to be overdone - should only be id (assuming this is unique) whether this a DB sequence number or the book's ISBN. Author and book category combination would normally not be considered to be unique (an author will normally write more than one book in a particular category)
Also I would think that the BOOK would have a FK back to the PUBLISHER table rather than the other way around as a Publisher willl publish more than one book but a book, at least an edition of a book, will only have one publisher.




 
Mag Wells
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, seems like when you reverse engineer using hibernate tools, it creates appropriate objects.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic