I am eagerly waiting the version of the XDoclet module supporting nested
objects...
The syntax looks very nice.
A question about the @ojb.modify-nested tag. Potentially, an object can
embed many instances of the same class.
For instance, a SimpleCustomer object can hold a billing and shipping
address.
A specific mapping attribute name - column name should be specified at
the nesting class level.
I would like to know if the @ojb.modify-nested tag will allow me specify
an alternate column name to deal with multiple nested objects of the
same class?
I would like to write things such as...
/**
* @ojb.class table="SIMPLE_CUSTOMER"
*/
public class SimpleCustomer implements java.io.Serializable
{
/**
* @ojb.nested
* @ojb.modify-nested name="streetName"
* column="SHIPPING_STREET_NAME"
* @ojb.modify-nested name="streetNumber"
* column="SHIPPING_STREET_NUMBER"
* @ojb.modify-nested name="zip"
* column="SHIPPING_ZIP_CODE"
*/
protected Address shippingAddress;
// or better... :-)
/**
* @ojb.nested
* @ojb.modify-nested name="*"
* column="BILLING_*"
*/
protected Address billingAddress;
/** @ojb.field column="NAME" */
protected String name;
...
}
Pierre
-----Original Message-----
From: Thomas Dudziak [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 06 January, 2004 11:33 AM
To: OJB Users List
Subject: Re: How to specify nested fields with ojb xdoclet?
The XDoclet module does not yet support nested objects, but it will in
the next release (end of january), perhaps even in the OJB 1.0 final.
The syntax will look like this (minor changes are possible):
/**
* @ojb.class table="CONTACT_PERSON"
*/
public class ContactPerson implements java.io.Serializable
{
/** @ojb.nested */
protected Address address;
/** @ojb.field column="NAME" */
protected String name;
...
}
/**
* Note that ojb.class is not necessary here for the nesting
* though the individual ojb.field tags are.
*/
public class Address implements java.io.Serializable {
/** @ojb.field column="STREET_NAME" */
protected String streetName
/** @ojb.field column="STREET_NUMBER" */
protected String streetNumber
/** @ojb.field column="ZIP_CODE" */
protected String zip;
...
}
This will result in something like (note the ordering):
<class-descriptor
class="be.gfdi.business.base.ContactPerson"
table="CONTACT_PERSON"
>
<field-descriptor
name="address::streetName"
column="STREET_NAME"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="address::streetNumber"
column="STREET_NUMBER"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="address::zip"
column="ZIP_CODE"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="name"
column="NAME"
jdbc-type="VARCHAR"
/>
...
</class-descriptor>
To change the ordering or ignore fields you could modify the nested
fields like this:
/**
* @ojb.class table="CONTACT_PERSON"
*/
public class ContactPerson implements java.io.Serializable
{
/**
* @ojb.nested
* @ojb.modify-nested name="streetName"
* id="2"
* @ojb.modify-nested name="streetNumber"
* id="3"
* @ojb.modify-nested name="zip"
* ignore="true"
*/
protected Address address;
/**
* @ojb.field column="NAME"
* id="1"
*/
protected String name;
...
}
which results in
<class-descriptor
class="be.gfdi.business.base.ContactPerson"
table="CONTACT_PERSON"
>
<field-descriptor
name="name"
column="NAME"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="address::streetName"
column="STREET_NAME"
jdbc-type="VARCHAR"
/>
<field-descriptor
name="address::streetNumber"
column="STREET_NUMBER"
jdbc-type="VARCHAR"
/>
...
</class-descriptor>
(This is a slightly contrieved example of the modify-nested tag as it
would suffice to use id for the "name" field).
Tom
---------------------------------------------------------------------
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]