Hi,
http://db.apache.org/ojb/tutorial3.html#using%20proxy%20classes
discusses the use of proxies in detail.
Essentially, if you want to use proxies for a SingleReference they
ultimately will
have to be interfaces so that OJB can generate a DynamicProxy for them.
Our Object model couldn't support that (not in a maintanable way), so what
we've done is to write a RelationshipHelper class that lazily loads a
relationship on demand.
We then implement the getter on the persistence class a bit like this :
public Country getCountry(){
RelationshipHelper.lazyLoad(this,"country");
return country;
}
I realise and acknowledge this isn't ideal, and probably won't help alot of
people, but it solves the problem for us.
Cheers,
Charles
>-----Original Message-----
>From: David Warnock [mailto:[EMAIL PROTECTED]]
>Sent: 13 February 2003 10:21
>To: [EMAIL PROTECTED]
>Subject: How to do Lazy Foreign Keys?
>
>
>Hi,
>
>I have solved my earlier problem with simple foreign key relationships
>and they now work.
>
>But how do I avoid loading the parent object before it is required?
>
>I know I can use a single proxy for a whole collection BUT what is the
>equivilent for single foreign key relationships like this
>
>
> <class-descriptor
> class="org.visres.contact.data.Country"
> table="Countries"
> >
> <field-descriptor
> name="countryId"
> column="CountryId"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"
> sequence-name="GEN_CountryId"
> />
> <field-descriptor
> name="name"
> column="Name"
> jdbc-type="VARCHAR"
> />
> </class-descriptor>
>
> <class-descriptor
> class="org.visres.contact.data.State"
> table="States"
> proxy="dynamic"
> >
> <field-descriptor
> name="stateId"
> column="StateId"
> jdbc-type="INTEGER"
> primarykey="true"
> autoincrement="true"
> sequence-name="GEN_StateId"
> />
> <field-descriptor
> name="name"
> column="Name"
> jdbc-type="VARCHAR"
> />
> <field-descriptor
> name="countryId"
> column="CountryId"
> jdbc-type="INTEGER"
> />
> <reference-descriptor
> name="country"
> class-ref="org.visres.contact.data.Country"
> >
> <foreignkey field-ref="countryId"/>
> </reference-descriptor>
> </class-descriptor>
>
>
>So when I load a State I don't want to load it's country unless I call
>state.getCountry().
>
>Thanks
>
>Dave
>--
>David Warnock, Sundayta Ltd. http://www.sundayta.com
>iDocSys for Document Management. VisibleResults for Fundraising.
>Development and Hosting of Web Applications and Sites.
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
This email and any attachments are strictly confidential and are intended
solely for the addressee. If you are not the intended recipient you must
not disclose, forward, copy or take any action in reliance on this message
or its attachments. If you have received this email in error please notify
the sender as soon as possible and delete it from your computer systems.
Any views or opinions presented are solely those of the author and do not
necessarily reflect those of HPD Software Limited or its affiliates.
At present the integrity of email across the internet cannot be guaranteed
and messages sent via this medium are potentially at risk. All liability
is excluded to the extent permitted by law for any claims arising as a re-
sult of the use of this medium to transmit information by or to
HPD Software Limited or its affiliates.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]