Hello Keith,

> Hi Thomas,
>
> I couldn't figure out if you are trying to use the Unmarshalling to fill
> the parent field...
>
> if so:
>
> You have to mark the 'parent' field as a reference and change the node
> type to attribute:
>
> ...
>    <field name="parent" type="Parent" reference="true">
>      <sql name="parent_id"/>
>      <bind-xml name="parent" node="attribute"/>
>    </field>
> ...
>
> the XML representation must also be an attribute containing the id of
> the parent,
> as such:
>
> <parent id="x">
>    <child parent="x">one</child>
>    <child parent="x">two</child>
> </parent>

Exactly this is, what I tried to prepend. I think XML has a tree-structure
to say <child> is a child of <parent> if it is a subelement. So why does
castor not have a possibility to define a backreference to a parent-element
if one specify this in the mapping file. How to take Data from XML to SQL
else?

Thomas

>
> --Keith
>
>
> Thomas Louis wrote:
> >
> > Hello,
> >
> > do I've found a genral problem?
> >
> > I'd like to save Data with JDO, that originally come from XML
unmarshalling
> > it with Castor.
> >
> > XML looks like that:
> >
> > <parent>
> >   <child>one</child>
> >   <child>two</child>
> > </parent>
> >
> > SQL-DDL looks like that:
> >
> > CREATE TABLE parent
> > (
> >  parent_id  MEDIUMINT NOT NULL,
> >   CONSTRAINT  PK_parent PRIMARY KEY ( parent_id )
> > );
> >
> > CREATE TABLE  sprach_eintrag
> > (
> >  child_id  MEDIUMINT NOT NULL,
> >  parent_id  MEDIUMINT,
> >  content  TEXT,
> >   CONSTRAINT  PK_child  PRIMARY KEY ( child_id )
> > );
> >
> > The class Parent has an arraylist containing the Elements which are
> > unmarshalled to Instances of class Child.
> >
> > The Mapping file looks like this:
> >
> > <mapping>
> > <class name="Parent" identity="id" key-generator="MAX">
> >   <map-to xml="parent" table="parent"/>
> >   <field name="id" type="integer">
> >     <sql name="parent_id" type="integer"/>
> >   </field>
> >   <field name="childs" type="Child" collection="arraylist">
> >     <sql many-key="parent_id"/>
> >     <bind-xml name="child" node="element"/>
> >   </field>
> > </class>
> > <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="content" type="java.lang.String">
> >     <sql name="content" type="varchar"/>
> >     <bind-xml name="string" node="text"/>
> >   </field>
> > </class>
> > </mapping>
> >
> > You can see, that the fields named "id" are not mapped to XML. I think
this
> > isn' nessecary.
> > The Problem is, that after storing the parent by
> >
> > Parent parent = (Parent)unmarshaller.unmarshal(new InputSource(new
> > FileReader(XmlFile)));
> > Database db = jdo.getDatabase();
> > db.begin();
> > db.create(parent);
> > db.commit();
> > db.close();
> >
> > The table child have two new lines with "one" and "two". But the column
> > parent_id is null and does not contain the generated ID parent_id of the
> > table parent.
> >
> > Only if the class Child have an field containing the parent_id it would
be
> > stored correctly. I tried to add this field and wrote a corresponding
> > mapping:
> >
> > <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="element"/>
> >   </field>
> >   <field name="content" type="java.lang.String">
> >     <sql name="content" type="varchar"/>
> >     <bind-xml name="string" node="text"/>
> >   </field>
> > </class>
> >
> > But this mapping does not fill the field Child.parent with the it's
parent
> > Element-object.
> >
> > Do you understand what I mean?
> >
> > Must I have an biderectional association in 1:many relationships to get
data
> > from XML to SQL?
> >
> > Please help. Don't know what to do.
> >
> > Thomas
> >
> > -----------------------------------------------------------
> > If you wish to unsubscribe from this mailing, send mail to
> > [EMAIL PROTECTED] with a subject of:
> >         unsubscribe castor-dev
>
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>

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

Reply via email to