• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Foreign Keys

 
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 !!
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!