Hi,

I have Java classes generated using Castor Code Generator,
and they works fine for XML-Java marshalling/unmarshalling.
I want to utilize the classes for Java-SQL mapping, too.

My question is how to create a reference from the dependent
class to the master one, in 1:m relationship.
The dependent appears in the content model of the master's
complex type definition in the XML schema.

In the Castor JDO, dependent objects must have reference to 
its master object. Finally, the reference is stored as a
foreign key in the dependent side table.

How can I treat such 1:m objects as master and dependents in JDO ?
Some subclasses of generated classes should be written by hand ?



For example, suppose a product has many details.
The XML schema looks like:
===========================================================
    <xsd:complexType name="productDetailType">
        <xsd:attribute name="id"   type="xsd:string" use="required" />
        <xsd:attribute name="name" type="xsd:string" use="required" />
    </xsd:complexType>

    <xsd:element name="product" type="productType" />

    <xsd:complexType name="productType">
        <xsd:sequence>
            <!-- Product has many Details. -->
            <xsd:element name="detail" type="productDetailType" 
                minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
        <xsd:attribute name="id"    type="xsd:string" use="required" />
        <xsd:attribute name="name" type="xsd:string" use="required" />
        .....
    </xsd:complexType>
===========================================================


A snippet of the generated classes:
===========================================================
public class ProductDetailType implements java.io.Serializable {
    private java.lang.String _id;
    private java.lang.String _name;
    .....
}

public class Detail extends ProductDetailType 
implements java.io.Serializable
{
    .....
}

public class ProductType implements java.io.Serializable {
    private java.lang.String _id;
    private java.lang.String _name;
    private java.util.Vector _detailList;
    .....
    public void addDetail(final Detail vDetail)
    throws java.lang.IndexOutOfBoundsException {
        this._detailList.addElement(vDetail);
    }
    .....
}
===========================================================


As you can find in the Castor example, the following code 
is required for master-dependents relation.
===========================================================
public class ProductDetailType implements java.io.Serializable {
    private java.lang.String _id;
    private java.lang.String _name;
    private Product _product;

    public void setProduct( final Product product )
    {
        _product = product;
    }
    .....
}

public class ProductType implements java.io.Serializable {
    private java.util.Vector _detailList;

    public void addDetail(final Detail vDetail) {
        .....
        this._detailList.addElement(vDetail);
        vDetail.setProduct(this);
    }
    .....
}
===========================================================


----
Akihito NAKAMURA @ AIST



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to