Thanks a lot.
That really cleared it up for me.
That brings me to two questions:
1) Why not change the name of the "many-key" attribute to something like "relationship-key" or "rel-key" ? It seems that a x - to - many mapping is dependent on 2 things: a relationship key and a collection type, whereas a one to one mapping like mine is a relationship key with an object type.
2) Has any thought been given to the use of proxy objects ( from JDK 1.3 on ) for dynamically loading up these dependent objects so it's only grabbed when needed? I mean, I'm *sure* thought has been given, but what is the current thinking.
Again, thanks for the help and for a great piece of software.
-a
-----Original Message-----
From: Patrick van Kann [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 22, 2002 4:14 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] one to one relationships
Hello,
Just a quick note -- There are two ways of achieving a one-to-one
mapping. That is why one-to-one discussions are a little confusing! The
following is a work-in-progress for a FAQ item on this topic. Imagine a
class Brochure that is to have a one-to-one relationship with
myapp.Product from the JDO examples (src/examples/jdo).
NB: In my model, the relationship between Product and Brochure is
composition -- hence the depends keyword in the mapping.
Approach 1
Treat as one-to-many but without collection.
Advantage: Requires no bi-directionality at the database level (see
Approach 2 below)
Disadvantage: Semantically confusing to use "many-key" since it is not
this type of relationship
References: Thomas Yip
(http://castor.exolab.org/list-archive/msg20458.html)
Margaret Martin
(http://castor.exolab.org/list-archive/msg20437.html)
Example Mapping:
In the myapp.Product mapping we add
<!-- Product has reference to Brochure
one brochure per product in a one-to-one mapping -->
<field name="brochure" type="myapp.Brochure">
<sql many-key="prod_id"/>
<xml name="brochure" node="element" />
</field>
Approach 2
Add foreign key relationships in both tables of the database, and map it
as follows. This means adding a field to the prod table called broch_id!
Advantage: Semantically more satisfying at a mapping level
Disadvantage: Bi-directional foriegn key relationship required at a
database level
References: Peter Jezenszky:
http://castor.exolab.org/list-archive/msg20409.html
Example Mapping:
<!-- Product has reference to Brochure
one brochure per product in a one-to-one mapping -->
<field name="brochure" type="myapp.Brochure">
<sql name="broch_id"/>
<xml name="brochure" node="element" />
</field>
The mapping for Brochure is the same in each case.
<!-- Mapping for Brochure -->
<class name="myapp.Brochure" identity="id" depends="myapp.Product">
<description>Brochure definition</description>
<map-to table="brochure" xml="brochure" />
<field name="id" type="integer">
<sql name="id" type="integer" />
<xml name="id" node="attribute"/>
</field>
<!-- Brochure has reference to Product,
one brochure may reference one product -->
<field name="product" type="myapp.Product" required="true">
<sql name="prod_id" />
<xml name="product" node="element" />
</field>
</class>
The table for brochure is
brochure
----------
id
prod_id
I hope this helps.
Patrick
Dominik Baranowski wrote:
> the scenario you describe with the set and getAddress methods is most
> definitely possible.
> how are you doing the mapping?
>
> -dom
>
> ----- Original Message -----
> *From:* Aadithya Deshpande <mailto:[EMAIL PROTECTED]>
> *To:* [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> *Sent:* Monday, October 21, 2002 3:11 PM
> *Subject:* [castor-dev] one to one relationships
>
> i just tried re-reading the one-to-one discussion on the mailing
> list that occurred a little while back and i'm still a bit confused.
>
> i'm trying to implement a 1-to-1 relationship of this type;
>
> MEMBER MEMBER_ADDRESS
> -------------- --------------------------------
> ID ID
> LOGIN STREET_ADDRESS
> PASSWORD CITY
> EMAIL STATE
>
>
> this is a one to one relationship tied together by ID ( obviously,
> i hope ).
>
> does this have to be mapped as an "extends" relationship? or can
> i do something similar to the master/detail relationship?
>
> ideally, i'd like to go down the master/detail style route.
>
> public class Member {
>
> private int id;
> private String login;
> private String password;
> private string email;
> private Address memberAddress;
>
> ..gets and sets..
>
> public void setAddress( Address p_address ) { this.memberAddress =
> p_address; }
> public Address getAddress( ) { return this.memberAddress; }
>
> }
>
> can't seem to make this happen. is this possible?
>
> Aadi Deshpande
> Director of Engineering
> ClubMom, Inc.
> 200 Madison Ave., 6th Floor
> New York, NY 10016
> tel 646.435.6562
> fax 646.435.6600
>
>
>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev
