MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
rtosi
Post subject: problem with foreign keys  PostPosted: Sep 02, 2004 - 11:13 AM



Joined: Jun 25, 2004
Posts: 2

Hi,
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 !!
 
 View user's profile Send private message  
Reply with quote Back to top
rileywc
Post subject:   PostPosted: Sep 02, 2004 - 03:40 PM
Veteran Member
Veteran Member


Joined: Dec 15, 2003
Posts: 10

I'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
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits