> Castor has no way to "magically" guess that you want to put a copy of
> the parent inside the child. So you can either use the approach I
> suggested above which explicitly expresses your desires, or you can
> handle the back-reference very easily yourself in your add/set method:

No, not magically, but the mapping could provide something like this with a
new node-type, I named it "parent-element"

<class name="Child" identity="id" key-generator="MAX" depends="Parent">
  <map-to xml="child" table="child"/>
  <field name="id" type="integer">
    <sql name="child_id"/>
  </field>
  <field name="parent" type="Parent">
    <sql name="parent_id"/>
    <bind-xml name="parent" node="parent-element"/>
                                   ^^^^^^^^^^^^
  </field>
  <field name="content" type="java.lang.String">
    <sql name="content" type="varchar"/>
    <bind-xml name="string" node="text"/>
  </field>
</class>

This would be a great solution.

> public void addChild(Child child) {
>    ...
>    child.setParent(this);
> }

Does this also work, if I unmarshall the data from XML. Which method does
the unmarshaller call to add childs? addChild(Child child)? setChild(Child[]
children)? setChild(int index, Child child)?

Thank you,
Thomas

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to