Hi,

Summary of problem: When I unmarshal a master object and its dependent
objects from previously marshalled XML, the dependent objects' properties
(Foreign Keys) that are of the parent's data type are not loaded and remain
null. 

Full description: I have an object model where: The Foo5 object has a
property bar5s which is a Vector collection of Bar5 objects. The Bar5
objects are dependent on the Foo5 object as specified in the mapping. The
Bar5 object has a field foo5 of type Foo5 which is the foreign key field in
Bar5.

Everything works fine when I create a Foo5, create a couple of Bar5s, add
the Bar5s to the Foo5 and call db.create(foo5) in a transaction. Also, when
I load a Foo5 from the database via JDO the object is populated correctly.
All Bar5s in the bar5s Vector are correctly populated as well.

The problem arises when I marshal a Foo5 to file and then unmarshal. The
marshalled output contains the Foo5 information and elements that represent
each Bar5 that is dependent on the Foo5. However, there is no foreign key
information represented in the Bar5 element data that has been marshalled
even though the mapping file contains an <xml...> element for this field.
(btw, I specify the mapping file to a mashaller before calling the marshal
method)  

Now the problem --- When I unmarshal a Foo5 object, all properties load
correctly including the Vector collection of Bar5s. EXCEPT that the Bar5
objects have a NULL value for their foo5 property.  This is problemmatic
because when I want to update the unmarshalled object, the update fails
because the NULL property resolves to a NULL value for the foreign key
column in the Bar5 database table.

Any help is appreciated. XSD and mapping below.

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
        
targetNamespace="http://www.zzz.com/castor/schemas/test/types";
        xmlns="http://www.zzz.com/castor/schemas/test/types";
        xmlns:ext="http://www.zzz.com/castor/schemas/test/externalTypes"; >

    <xsd:import
namespace="http://www.zzz.com/castor/schemas/test/externalTypes";
        schemaLocation="ExternalDataTypes.xsd" />

   <xsd:element name="foo5">
        <xsd:annotation>
            <xsd:documentation>A simple representation of a foo5
object</xsd:documentation>
        </xsd:annotation>

        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="name" type="xsd:string" />
                <xsd:element name="date" type="xsd:dateTime" />
                <xsd:element name="bar5s" type="ext:Bar5"
maxOccurs="unbounded" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="bar5">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="name" type="xsd:string" />
                <xsd:element name="date" type="xsd:dateTime" />
                <xsd:element name="foo5" type="ext:Foo5" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
                           "http://castor.exolab.org/mapping.dtd";>
<mapping>

  <!--  Mapping for Foo5-->
  <class name="foo5.Foo5" identity="id.id">
    <description>Foo5 object</description>
    <map-to table="foo5" xml="foo5" />

    <field name="id.id" type="string">
      <sql name="id" type="char"/>
      <xml name="idField" node="attribute"/>
    </field>

    <field name="name" type="string">
      <sql name="name" type="char"/>
      <xml node="element"/>
    </field>

    <field name="date" type="date">
      <sql name="date" type="date"/>
      <xml node="element" />
    </field>

    <!--foo5 has a 1:many reference to Bar5-->
    <field name="bar5s" type="foo5.Bar5" required="true"
         collection="vector" set-method="setBar5sVector"
get-method="getBar5sVector">
        <sql many-key="foo5_id" />
        <xml name="bar5s" node="element" />
    </field>
  </class>

  <class name="foo5.Bar5" identity="id.id" depends="foo5.Foo5">
    <map-to table="bar5" xml="bar5" />

    <field name="id.id" type="string">
      <sql name="id" type="char" />
      <xml name="id" node="attribute"/>
    </field>

    <field name="name" type="string">
      <sql name="name" type="char"/>
      <xml node="element" />
    </field>

    <field name="date" type="date">
      <sql name="date" type="date"/>
      <xml node="element" />
    </field>

    <!--foreign key field from foo5.Foo5.bar5s field-->
    <field name="foo5" type="foo5.Foo5">
      <xml name="foo5FK" node="element" />
      <sql name="foo5_id" />
    </field>
  </class>

</mapping>

Richard Davis

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

Reply via email to