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\xBE 听趾 倣痺蓍\xED
\xBE 听蜀聽蜩緕齡鱇゜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


Reply via email to