• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Foreign Keys

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, seems like when you reverse engineer using hibernate tools, it creates appropriate objects.

Thanks.
 
Forget Steve. Look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic