Hi Akihito,

in that case you should be able to define a bidirectional relation
between Product and Detail in your XSD. This means Product has a list of
Details while Detail has a reference to the Product it belongs to. As
I'm not an expert at writing XSD's so I can not tell you exactly how to
achive this but I think you have to work with xsd:ID and xsd:IDREF. As
far as I know it should look something like:

    <xsd:complexType name="productDetailType">
        <xsd:attribute name="id"   type="xsd:string" use="required" />
        <xsd:attribute name="name" type="xsd:string" use="required" />
        <xsd:attribute name="product" type="xsd:IDREF" 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:ID" use="required"/>
        <xsd:attribute name="name" type="xsd:string" use="required" />
        .....
    </xsd:complexType>


If you have managed to link Product and Detail in both directions you
should have a Product property in Detail class which allows you to map
the 1:n relation for JDO as usual.

Regards
Ralf


Akihito Nakamura schrieb:
> Thank you Ralf.
>
>
>   
>> if you do not have control over XSD there is only one option you can
>> try. You can treat the relation between Product and Detail as n:m. For a
>> n:m relation you will create a seperate relation table that stores which
>> Detail belongs to which Product. It should be possible to define such a
>> relation only on the Product side. Informations about how to map n:m
>> relations are included in Castor docs.
>>     
>
> OK.
>
> If I can modify the XSD, do I have more sophisticated solutions ?
>
>
>   
>> Akihito Nakamura schrieb:
>>     
>>> 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
>>>
>>>
>>>   
>>>       
>> -- 
>>
>> Syscon Ingenieurb?Ralf Joachim
>> Raiffeisenstra゜e 11
>> 72127 Kusterdingen
>> Germany
>>
>> Tel.   +49 7071 3690 52
>> Mobil: +49 173 9630135
>> Fax    +49 7071 3690 98
>>
>> Internet: www.syscon.eu
>> E-Mail: [email protected]
>>
>> Sitz der Gesellschaft: D-72127 Kusterdingen
>> Registereintrag: Amtsgericht Stuttgart, HRB 382295
>> Gesch臟tsleitung: Jens Joachim, Ralf Joachim
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>     
>
>
> ----
> Akihito NAKAMURA @ AIST
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>   

-- 

Syscon Ingenieurbu"ro fu"r Me?- und Datentechnik GmbH
Ralf Joachim
Raiffeisenstra?e 11
72127 Kusterdingen
Germany

Tel.   +49 7071 3690 52
Mobil: +49 173 9630135
Fax    +49 7071 3690 98

Internet: www.syscon.eu
E-Mail: [email protected]

Sitz der Gesellschaft: D-72127 Kusterdingen
Registereintrag: Amtsgericht Stuttgart, HRB 382295
Gescha"ftsleitung: Jens Joachim, Ralf Joachim

Reply via email to