the docs may not be clear, but the examples are pretty clear.
you have to map the field first:
example:
<field-descriptor
name="operatingUnitUUID" <---- the name of the getter/setter or property that
OJB will set. This is NOT the reference, but the key value (string, int, whatever)
column="operating_unit_uuid" <------ the name of the column in the database that
holds the value
jdbc-type="VARCHAR" <--- the type
conversion="org.apache.ojb.broker.accesslayer.conversions.BlankString2NullFieldConversion">
<--- a conversion (optional)
</field-descriptor>
then the referenced object:
<reference-descriptor
name="operatingUnit" <-- the name of the getter/setter or property that OJB will
set the object into
class-ref="com.foo.OperatingUnitImpl"> <-- the java type
<foreignkey field-ref="operatingUnitUUID"/> <-- the field-descriptor name that
will be used to find the foreign key value.
</reference-descriptor>
now, the class you are mapping must have:
getOperatingUnitUUID
setOperatingUnitUUID
getOperatingUnit
setOperatingUnit
in order to map the OperatingUnitImpl as a referenced object(1:1).
Why have both a field mapping AND a reference mapping? For lazy loading. In the case
where lazy loading is on, you need to load the "handle" in this case the appropriate
foreign key in order to look up the reference object later.
HTH,
Matthew
-----Original Message-----
From: Robert S. Sfeir [mailto:[EMAIL PROTECTED]]
Sent: Thursday, February 13, 2003 8:34 AM
To: oJB List
Subject: foreign keys... again
Still a bit confused, If I have this:
<class-descriptor class="net.sfeir.business.RequestBO" table="REQUESTS">
<field-descriptor name="assignedToID" column="assignedTo"
jdbc-type="INTEGER"/>
...
and I want to setup a foreign key from assignedToID to another table
called Users and the column there is called userID
I added this as the foreign-key reference:
<reference-descriptor name="userBO"
class-ref="net.sfeir.security.business.UserBO">
<foreignkey field-ref="userID"/>
</reference-descriptor>
But it doesn't make any sense, if I put assignedToID in the field-ref,
how does it know the column I am mapping? If I put the userID like I
did in the field-ref how does it know that I am mapping assignedToID?
You can't always expect the table column names to match, most of the
time they won't.
I'm missing something here that would let me tell the descriptiptor.
The RequestBO object has a getter and setter which get back a UserBO as
suggested earlier, but even if it does a getUserBO() and it gets the
UserBO back, UserBO doesn't have a method called getAssignedTOID() nor
do I want to do that because that's breaking the OO rules of the
framework.
I'm totally confused right now and unfortunately, the docs are not very
clear.
R
--
Robert S. Sfeir
Senior Java Engineer
National Institutes of Health
Center for Information Technology
Department of Enterprise Custom Applications
[EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]