Keith Visco wrote:
> 
> Hi Jim,
> 
> Yes you need to change the input XML, which must contain the "foo"
> reference:
> 
> It should look something like the following:
> <foo id="42">
>    <bar foo="42">
>       <greeting>hello world</greeting>
>    </bar>
> </foo>

That should read:

 <foo id="42">
    <bar parent="42">
       <greeting>hello world</greeting>
    </bar>
 </foo>

I do have a working example of this if you want me to send it to you.

--Keith

> 
> When you marshal from Castor you'll see that Castor creates the XML like
> this.
> 
> Currently this is the only way to get Castor to automatically put the
> Foo parent instance into Bar.
> 
> In the future we may have something that will do it automatically
> something as simple as:
> 
> <field name="##parent"/>
> 
> Is all that is really needed...
> 
> But for now, you need to use ID/IDREF.
> 
> --Keith
> 
> Jim Otte wrote:
> >
> > Keith,
> > Thanks again for your suggestions. I tried your ideas-
> > and have found:
> > 1. I listed the identity=id in the <class> element of
> > Foo - and the parent field under Bar as <bind-xml
> > node="attribute" reference="true"  /> yet I still do
> > not get the expected result- just a null pointer when
> > referencing the parent fields.
> > Does the input xml have to change at all- I have
> > changed only the mapping xml- or the classes?
> > I need to have Bar as a child of Foo so I need to have
> > an element for Bar:
> >  <field name="bar" type="Bar">
> >                         <bind-xml name="bar"
> > node="element"/>
> >                 </field>
> >
> > or else Castor complains :
> > unable to find FieldDescriptor for 'bar' in
> > ClassDescriptor of foo
> >
> > for the xml....So am I just not seeing something here
> > or is it still a limitation for a relation such as
> > this?
> >
> > Thanks for your input,
> > Jim
> >
> > --- Keith Visco <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > >
> > > Jim Otte wrote:
> > > >
> > > > Keith,
> > > >
> > > > Thanks for the lead- I believe that is the right
> > > > trail- however, when I implement the ID/IDREF
> > > > attributes- I still do not get the reference to
> > > the
> > > > parent from the child - note my differences from
> > > your
> > > > example:
> > > > 1. The Parent Foo has the child Bar class as an
> > > > attribute: Foo has Bar bar; as a class member.
> > >
> > > Yes...that's understood...I saw the classes you
> > > listed in your original
> > > post. When using ID/IDREF however you have to mark
> > > them in the
> > > mapping file as attributes. This is a limitation on
> > > ID/IDREF and
> > > the limitation comes from DTDs. ID/IDREF must be
> > > specified as
> > > attributes in the XML instance.
> > >
> > > > 2. It is not necesarily the case that Bar extends
> > > Foo
> > > > (am not certain if that is what was being
> > > understood)-
> > > > Bar should just be a child class attribute with a
> > > > reference to the parent- no special relation
> > > outside
> > > > of that.
> > >
> > > Yes...no misunderstanding here. My example
> > > demonstrates a simple
> > > parent-child relationship.
> > >
> > > > 3. It is possible that Foo may have more than 1
> > > field
> > > > as "ID" or primary -key.
> > >
> > > Castor doesn't yet have the ability to support
> > > multiple
> > > fields as the key (actually it doesn't support
> > > key/keyref yet)
> > >
> > > You can work around this limitation by providing one
> > > field that
> > > incorporates both keys such as:
> > >
> > > public String getIdentity() {
> > >     return key1 + "," + key2;
> > > }
> > >
> > > > 4. The parent reference is a type node="element"
> > > > rather than "attribute"- although I get the same
> > > > result even if I do switch that:
> > > > Nevertheless- when I use the following mapping:
> > >
> > > Both the identity field and the reference field need
> > > to be marked as
> > > attributes.
> > >
> > > --Keith
> > >
> > >
> > > >
> > > > <class name="tudo.foobar.castor.domain.Foo"
> > > > identity="id">
> > > >                 <map-to xml="foo"/>
> > > >
> > > >                 <field name="id"
> > > > type="java.lang.String" >
> > > >                         <bind-xml name="id"
> > > > node="element"/>
> > > >                 </field>
> > > >
> > > >                 <field name="bar" type="Bar">
> > > >                         <bind-xml name="bar"
> > > > node="element"/>
> > > >                 </field>
> > > >      </class>
> > > >
> > > >      <class name="Bar"  >
> > > >                 <map-to xml="bar"/>
> > > >
> > > >                 <field name="greeting"
> > > > type="java.lang.String">
> > > >                         <bind-xml name="greeting"
> > > > node="element"/>
> > > >                 </field>
> > > >
> > > >                 <field name="parent" type="Foo" >
> > > >                         <bind-xml name="foo"
> > > > reference="true" />
> > > >                 </field>
> > > >      </class>
> > > >
> > > > with the classes:
> > > > public class Foo {
> > > >         public Bar bar;
> > > >         public String id;
> > > >
> > > > and
> > > >
> > > > public class Bar{
> > > >
> > > >         public String greeting;
> > > >         public Foo parent;
> > > >
> > > > and xml:
> > > > <foo>
> > > >         <id>42</id>
> > > >         <bar>
> > > >                 <greeting>hello world</greeting>
> > > >         </bar>
> > > > </foo>
> > > >
> > > > and run the test with:
> > > >
> > > > System.out.println(foo.getBar().getGreeting());
> > > >
> > > >
> > >
> > System.out.println(foo.getBar().getParent().getId());
> > > >
> > > > I would expect:
> > > >
> > > > hello world
> > > > 42
> > > >
> > > > Instead I still get:
> > > >
> > > > hello world
> > > > java.lang.NullPointerException
> > > >
> > > > The Child Bar class does not seem to get a
> > > reference
> > > > to the parent Foo even using the ID and IDREF
> > > > tags....although I may very well be mis-applying
> > > them.
> > > >
> > > > Any further thoughts/corrections would be most
> > > > welcome-
> > > > Thanks again for the help- I have been racking my
> > > > brains on this for quite awhile....
> > > >
> > > > Jim
> > > >
> > > > --- Keith Visco <[EMAIL PROTECTED]> wrote:
> > > > >
> > > > >
> > > > > Jim,
> > > > >
> > > > > Castor supports parent-child relationships via
> > > > > ID/IDREF and can be
> > > > > expressed as such in a mapping file:
> > > > >
> > > > >
> > > > > <class name="Foo" identity="id">
> > > > >    <field name="id" type="string"/>
> > > > > </class>
> > > > >
> > > > > <class name="Bar">
> > > > >   <field name="parent" type="Foo">
> > > > >     <bind-xml node="attribute"
> > > reference="true"/>
> > > > >   </field>
> > > > > </class>
> > > > >
> > > > > Note the identity="id" specified on the Foo
> > > class
> > > > > mapping. And also note
> > > > > the reference="true" specified on the bind-xml
> > > > > element for the parent
> > > > > field in the Bar class mapping.
> > > > >
> > > > >
> > > > > I hope that helps.
> > > > >
> > > > > --Keith
> > > > >
> > > > > Jim Otte wrote:
> > > > > >
> > > > > > Ralf,
> > > > > >
> > > > > > Thanks for your reply!
> > > > > > I tried your suggestion- by modifying the
> > > domain
> > > > > > objects Foo and Bar- Now when I run the test
> > > class
> > > > > I
> > > > > > get the following error:
> > > > > >
> > > > > > org.xml.sax.SAXException: unable to add 'bar'
> > > to
> > > > > <foo>
> > > > > > due to the following exception:
> > > > > > >>>--- Begin Exception ---<<<
> > >
> > === message truncated ===
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Mail SpamGuard - Read only the mail you want.
> > http://antispam.yahoo.com/tools
> >
> > -----------------------------------------------------------
> > 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