Re: Hierarchical relationship problems

From: Filip Balas (fbala..mail.com)
Date: Fri Apr 22 2005 - 11:27:41 EDT

  • Next message: Sami Mohammed: "Re: Null Pointer error"

    Ummmm, not exactly sure what everyone means
    by backwards in this context. But I did use the cayenne
    modeler to create the relationships and the output I
    posted previously was from the logger in the eclipse console,
    so again generated by cayenne. I did nothing but write
    a little test loop to go through each root location and
    try to fetch children.

    Each Location has the following attributes:
    id (primary key)
    parent_id (id of the parent, can be null)
    description (name of location)

    Source is a Location.
    Target is a Location.

    Now the child relationship states that if:
    Source.id = Target.parent_id
    Then the target is your child.

    The parent relationship states that if:
    Source.parent_id=Target.id
    Then target is your parent.

    I am not a proud man, please correct me
    if I'm not understanding how the cayenne
    modeler iterprets the mapping of these
    things ;-D

    Filip

    On 4/22/05, Cris Daniluk <cris.danilu..mail.com> wrote:
    > Actually, it looks backward to me too (though no morning coffee yet,
    > so maybe you're right)... you know that if the relationships are
    > backward and you use Cayenne to create the tree, then of course
    > reading it will be backward too, right? Sounds like you were using
    > Cayenne for both ends...
    >
    > And of course, getChildren should always be a toMany.
    >
    > On 4/22/05, Filip Balas <fbala..mail.com> wrote:
    > > Well would you care to share this strange thinking
    > > with the group? Considering that the 'parent' relationship
    > > works as expected, it seems unlikely that my
    > > relation is upside-down. If I were to invert the relation
    > > (which I did try before posting) then getChildren returns
    > > one obejct (and not a list as it should) which is it's
    > > parent. 'getParent' then becomes the problem.
    > >
    > > Filip
    > >
    > >
    > > On 4/22/05, Jürgen Saar <jsaa..eb.de> wrote:
    > > > I've had the same problem with self referencing,
    > > > on my first try.
    > > >
    > > > Your relation is upside-down
    > > >
    > > > It needs a little strange thinking to get it right.
    > > >
    > > > cayenne-use..bjectstyle.org schrieb am 22.04.05 00:35:02:
    > > > >
    > > > > I'm not sure if this has already been covered as
    > > > > there doesn't seem to be a search facility for the
    > > > > mailing list.
    > > > >
    > > > > My problem is that I have a simple hierarchy with
    > > > > locations. A location can have child locations and
    > > > > vice verca can have a parent:
    > > > >
    > > > > Schema:
    > > > > --------------
    > > > > id
    > > > > parent_id
    > > > > description
    > > > >
    > > > > Now I have modeled this relationship and the modeler
    > > > > generated the following:
    > > > >
    > > > > <db-entity name="IMV_locations" schema="dbo" catalog="GPSForecast">
    > > > > <db-attribute name="description" type="VARCHAR" length="75"/>
    > > > > <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
    > > > > isMandatory="true" length="10"/>
    > > > > <db-attribute name="parent_id" type="INTEGER" length="10"/>
    > > > > </db-entity>
    > > > >
    > > > > <db-relationship name="rel_children" source="IMV_locations"
    > > > > target="IMV_locations" toMany="true">
    > > > > <db-attribute-pair source="id" target="parent_id"/>
    > > > > </db-relationship>
    > > > >
    > > > > <db-relationship name="rel_parent" source="IMV_locations"
    > > > > target="IMV_locations" toMany="false">
    > > > > <db-attribute-pair source="parent_id" target="id"/>
    > > > > </db-relationship>
    > > > >
    > > > > <obj-relationship name="children" source="Location" target="Location"
    > > > > deleteRule="Cascade"
    > > > > db-relationship-path="rel_children.rel_children"/>
    > > > >
    > > > > <obj-relationship name="parent" source="Location" target="Location"
    > > > > db-relationship-path="rel_parent.rel_parent"/>
    > > > >
    > > > > Now when I run some test code to build a tree in tapestry, the
    > > > > following statement gets genereated when I try to fetch children:
    > > > >
    > > > > SELECT t0.description, t0.id, t0.parent_id
    > > > > FROM dbo.IMV_locations t0, dbo.IMV_locations t1
    > > > > WHERE t0.parent_id = t1.id AND (t1.parent_id = ?) [bind: 1]
    > > > >
    > > > > This however incorrect, it should read:
    > > > >
    > > > > SELECT t0.description, t0.id, t0.parent_id
    > > > > FROM dbo.IMV_locations t0, dbo.IMV_locations t1
    > > > > WHERE t0.parent_id = t1.id AND (t1.id = ?) [bind: 1]
    > > > >
    > > > > Has anyone else had this problem?
    > > > > Filip
    > > >
    > > > __________________________________________________________
    > > > Mit WEB.DE FreePhone mit hoechster Qualitaet ab 0 Ct./Min.
    > > > weltweit telefonieren! http://freephone.web.de/?mc=021201
    > > >
    > > >
    > >
    > > --
    > > Cell : 403.461.7895
    > > Work: 403.770.1534
    > > MSN: fbala..otmail.com
    > >
    >

    -- 
    Cell  : 403.461.7895
    Work: 403.770.1534
    MSN:  fbala..otmail.com
    



    This archive was generated by hypermail 2.0.0 : Fri Apr 22 2005 - 11:27:43 EDT