Discussion:
[Middlegen-user] Relation.java
Steve Knight
2002-02-19 17:09:05 UTC
Permalink
Aslak,
I am having trouble fixing the RelationshipRole names...in Relation.java you set _isRightMany to true, even when the tables have a one-to-one relationship (as specified in the GUI). How can I find out the true cardinality for the _rightTable? Or should I say, what is the easiest way? So far I haven't had any luck...I keep getting lost when trying to follow the trail. I need to know this value so I can set the appropriate role names.

Thanks,

Steve
a***@netcom.no
2002-02-19 17:32:04 UTC
Permalink
Hi Steve,

Relation's constructor makes a guess about the foreign key side's
multiplicity. -Or rather an assumption: That the side with the FK is always
many. After all, the database doesn't give any info about multiplicity
(AFAIK) -but see below.

Remember that the Relation objects are created at db parse time, even before
the GUI is created. When the GUI is up, you can change the multiplicity. It
happens via a call to RelationshipRole.setTargetMany.

What do you mean by "true" cardinality for the right table? Is this
something the DatabaseMetaData would know about? Here is a guess:

"A relationship can be assumed to be 1:1 if the foreign key is also a
primary key, because that would disallow more than one row with that foreign
key."

If you agree on this, I could implement some smart checking on this in
MiddlegenPopulator and set right to many if fk is also a pk.

Aslak

-----Original Message-----
From: middlegen-user-***@lists.sourceforge.net
[mailto:middlegen-user-***@lists.sourceforge.net]On Behalf Of Steve Knight
Sent: 19. februar 2002 20:10
To: middlegen-***@lists.sourceforge.net
Subject: [Middlegen-user] Relation.java


Aslak,
I am having trouble fixing the RelationshipRole names...in Relation.java you
set _isRightMany to true, even when the tables have a one-to-one
relationship (as specified in the GUI). How can I find out the true
cardinality for the _rightTable? Or should I say, what is the easiest way?
So far I haven't had any luck...I keep getting lost when trying to follow
the trail. I need to know this value so I can set the appropriate role
names.

Thanks,

Steve
Steve Knight
2002-02-20 01:29:02 UTC
Permalink
Ok, gotcha Aslak...I managed to get it working now. Thanks for setting me
straight.
So now, when you change the multiplicity for the relation, the relationship
role names are updated.
For example:
1 -> 1 = CarHasDriver, DriverHasCar
1 -> * = CarHasDrivers, DriversForCar
* -> * = CarsForDrivers, DriversForCars

I guess I could have come up with a better naming scheme, but this makes
enough sense. I had to take out the hyphens in order for it to work with
MVCSoft's pm. Also, the relation name must not have hyphens (CarDriver).
So far, this seems to be working. But I have not tested many-to-many (not a
priority)...does Middlegen support this? I seem to remember seeing those
bits coded out. I added some tags so that the JavaDocs created for the cmr
field are of the correct type (java.util.Collection, or EJBLocal, depending
on multiplicity).

I did notice another problem that maybe you can help me with. When making
the relationship unidirectional, you must specify the target-ejb and
target-role-name for the opposite side or XDoclet build will fail when
generating the descriptor. We need something like the following, but how
can I get the beanName of the target ejb? I could probably use a hack to
make this work, but is there a graceful way to get the target ejb name?

* @ejb:relation
* name="<XDtMg:relationName/>"
*
role-name="<XDtMg:relationshipRoleName/>"<XDtMg:ifIsRelationUnidirectional>
* target-ejb="???"
* target-role-name="???"</XDtMg:ifIsRelationUnidirectional>

Thanks,

Steve

----- Original Message -----
From: <***@netcom.no>
To: "Steve Knight" <***@hotmail.com>;
<middlegen-***@lists.sourceforge.net>
Sent: Tuesday, February 19, 2002 2:31 PM
Subject: RE: [Middlegen-user] Relation.java
Post by a***@netcom.no
Hi Steve,
Relation's constructor makes a guess about the foreign key side's
multiplicity. -Or rather an assumption: That the side with the FK is always
many. After all, the database doesn't give any info about multiplicity
(AFAIK) -but see below.
Remember that the Relation objects are created at db parse time, even before
the GUI is created. When the GUI is up, you can change the multiplicity. It
happens via a call to RelationshipRole.setTargetMany.
What do you mean by "true" cardinality for the right table? Is this
"A relationship can be assumed to be 1:1 if the foreign key is also a
primary key, because that would disallow more than one row with that foreign
key."
If you agree on this, I could implement some smart checking on this in
MiddlegenPopulator and set right to many if fk is also a pk.
Aslak
-----Original Message-----
Sent: 19. februar 2002 20:10
Subject: [Middlegen-user] Relation.java
Aslak,
I am having trouble fixing the RelationshipRole names...in Relation.java you
set _isRightMany to true, even when the tables have a one-to-one
relationship (as specified in the GUI). How can I find out the true
cardinality for the _rightTable? Or should I say, what is the easiest way?
So far I haven't had any luck...I keep getting lost when trying to follow
the trail. I need to know this value so I can set the appropriate role
names.
Thanks,
Steve
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Loading...