- This topic has 1 reply, 2 voices, and was last updated 20 years, 2 months ago by Walter Riley.
-
AuthorPosts
-
rtosiMemberHi,
I’ve a problem with foreign keys:I have a table Resources like this : rid (pk) – cid – rname
I’have to create another table like this : did (pk) – dep- rid1 (fk) -rid2(fk)
I have 2 EJB-CMP : ResourcesBean and DepBean for the first and the second table. In ResourceBean I have getRid() and setRid().
In the DepBean I have to use setRid1() and setRid2().
For getter and setter rid1 I have :
/**
* @ejb.relation
* name=”did-rid1″
* role-name=”dep-has-rid1″
* target-ejb = “Resource”
*
* @jboss.relation related-pk-field = “rid”
* fk-column = “rid1″
*
*
*
*/
public abstract ResourceLocal getRid1();public abstract void setRid1(ResourceLocal c);
…and for rid2 ???
I can’t use :
/**
* @ejb.relation
* name=”did-rid1″
* role-name=”dep-has-rid1”
* target-ejb = “Resource”
*
* @jboss.relation related-pk-field = “rid”
* fk-column = “rid2”
*
*
*
*/
public abstract ResourceLocal getRid2();public abstract void setRid2(ResourceLocal c);
….beacuse there is the same role-name and the same name…..
What is the solution…..I tried a lot of tricks but I’m not able to resolve this problem….
Thank you very much for the answer !!
Walter RileyMemberI’ll try to restate your problem in different words as I understand it.
You have two tables, call one table Person, call the other Marriage. Your problem results from tring to put two foreign keys in a Marriage record to relate back to the husband and wife entries in the Person table.
This is usually handled by putting a foreign key in the Person table and then having two records in the Person table point to one Marriage entry. This is just a specific example of a many-to-one relationship, namely 2 to 1. By putting the foreign key in the other table, you can easily change the relationship to n to 1 if required without having to change the structure of a table in order to add more foreign keys.
Hope this helps,
Walter -
AuthorPosts