• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate foreign key

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I am not strong in Database concepts,

I am having two tables,
User and Salary

In User table UserID is my primary key and in Salary table UserID and Salary_Date are composite keys. How can i set UserId as foreign key in Salary table? Can i use cascade on delete through Salry mapping file?

Please help me out if it is possible or please let me know where i did wrong?

Thanks in Advance,

Cheenath.
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Cheenath Ajay:
Dear All,

I am not strong in Database concepts,

I am having two tables,
User and Salary

In User table UserID is my primary key and in Salary table UserID and Salary_Date are composite keys. How can i set UserId as foreign key in Salary table? Can i use cascade on delete through Salry mapping file?

Please help me out if it is possible or please let me know where i did wrong?

Thanks in Advance,

Cheenath.



My preference would be for Salary to have a non-composite key. Don't include SALARY_DATE as part of the key.

USER_ID can be foreign key in SALARY:

 
Cheenath Ajay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply!!

but my situation is like sal_datae and userID should be composite key and i cant avoid that by making it as primary key, is there any way like that?

Hope you can help me to find a solution.

Thanks again

Cheenath
 
Cheenath Ajay
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Leave the matter of Salary table, just imagine Group table where a User will be having only one group and a Group can have more than one User

USERID+GroupID so it should be a composite key in Group table, am i righ


Please help me out!!

Cheenath
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forget composite keys altogether, use surrogate keys (like oids) instead of natural keys (like actual meaningful data columns), and use a combination of not null and unique constraints to get the data integrity right. Then, you will have no problem with referential stuff, because you simply reference a surrogate key from one table in another.
 
Can't .... do .... plaid .... So I did this tiny ad instead:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic