| Author |
Hibernate foreign key
|
Cheenath Ajay
Ranch Hand
Joined: Jan 26, 2006
Posts: 32
|
|
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.
|
 |
Michael Duffy
Ranch Hand
Joined: Oct 15, 2005
Posts: 163
|
|
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
Joined: Jan 26, 2006
Posts: 32
|
|
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
Joined: Jan 26, 2006
Posts: 32
|
|
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
|
 |
Emanuel Kadziela
Ranch Hand
Joined: Mar 24, 2005
Posts: 186
|
|
|
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.
|
 |
 |
|
|
subject: Hibernate foreign key
|
|
|