Re: Hierarchical relationship problems

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Apr 27 2005 - 18:34:53 EDT

  • Next message: Filip Balas: "Re: Hierarchical relationship problems"

    Doublecheck that you cleared those bogus flattened relationships.

    Read-only relationships are usually generated for all flattened
    relationships that Cayenne treats are non-updateable (i.e. all except m:n
    with a single join table). I suspect this is the cause of the problem.

    Andrus

    > I didn't notice this before but it appears cayenne
    > did not generate modifiers for the hierarchical class?
    >
    > What I mean is this:
    >
    > I HAVE:
    > Location getParent()
    > List getChildren();
    >
    > I am MISSING:
    > setParent(Location)
    > addToChildren(Location)
    > removeFromChildren(Location)
    >
    > I have checked to make sure I didn't inadvertantly
    > make the entity read-only. Any suggestions?
    >
    > Thanks,
    > Filip
    >
    >
    > On 4/25/05, Filip Balas <fbala..mail.com> wrote:
    >> Just a quick update so that no one wastes anymore
    >> time on this other than me. It appears that with the
    >> clean test, cayenne handles everything just fine.
    >>
    >> There must be something else in how I've used the
    >> modeler or set up the relationships in the database
    >> that is causing this to happen.
    >>
    >> Thanks for your input Andrus, just know that there is
    >> a test case for this was motivation enough to prove
    >> myself wrong.
    >>
    >> Cheers,
    >> Filip
    >>
    >>
    >> On 4/25/05, Filip Balas <fbala..mail.com> wrote:
    >> > Hmmm, okay I don't like to blame someone else's code
    >> > unless I'm 100% sure. Later today I will set up a purely
    >> > clean test (seperate table, seperate map, sperate test class). If
    >> this doesn't work I'll submit a bug...
    >> >
    >> > Thanks again,
    >> > Filip
    >> >
    >> > On 4/25/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    >> > > I am still dubious that this is Cayenne problem as we have test
    >> cases that cover this situation. So I recommend doublechecking
    >> that you don't have your old incorrect DataMap sitting somewhere
    >> in the classpath, and also check if it works with Cayenne 1.1.1
    >> (unless your code depends heavily on 1.2 API making this
    >> impossible).
    >> > >
    >> > > If it still doesn't work, please submit a bug report containing
    >> DataMap XML file and a code snippet that trigers this fetch.
    >> > >
    >> > > Andrus
    >> > >
    >> > >
    >> > > > I'm on the bleeding edge (could be why I'm having the
    >> > > > problem) cayenne 1.2M3.
    >> > > >
    >> > > > Filip
    >> > > >
    >> > > >
    >> > > > On 4/25/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    >> > > >> You shouldn't have to do anything special. Cayenne (including
    >> the Modeler) works fine with simple parent-child hierarchies.
    >> For "children" I expect the generated query to look even
    >> simpler:
    >> > > >>
    >> > > >> SELECT t0.description, t0.id, t0.parent_id
    >> > > >> FROM dbo.IMV_locations t0, dbo.IMV_locations t1
    >> > > >> WHERE t0.parent_id = ? [bind: 1]
    >> > > >>
    >> > > >> So ... What version of Cayenne do you have? There was a bug
    >> long time ago that messed it up, but I am fairly sure it is
    >> fixed in 1.1 final and 1.1.1 releases.
    >> > > >>
    >> > > >> Andrus
    >> > > >>
    >> > > >>
    >> > > >> > Hi Andrus,
    >> > > >> >
    >> > > >> > Yes that makes perfect sense. I didn't catch that error, I
    >> just
    >> > > >> assumed the modeler would generate the right xml when
    >> > > >> > I selected the proper source and target.
    >> > > >> >
    >> > > >> > However, even when I corrected the xml manually to your
    >> suggestion, I still have the following statement generated by
    >> cayenne:
    >> > > >> >
    >> > > >> > 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]
    >> > > >> >
    >> > > >> > I need it to 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]
    >> > > >> >
    >> > > >> > In another spot in my code I have a hierarchy set up but it
    >> is a many to many (map, not tree) and cayenne seems
    >> > > >> > to deal with that beautifully. To achieve this I have an
    >> > > >> intermediate table that maps locations to one another. Will I
    >> have to add
    >> > > >> > this extra table with a one-To-one constraint to ensure a
    >> tree
    >> > > >> structure and not a map?
    >> > > >> >
    >> > > >> > Thanks to all who have answered.
    >> > > >> > Your help is greatly appreciated.
    >> > > >> > Filip
    >> > > >> >
    >> > > >> >
    >> > > >> >
    >> > > >> > On 4/24/05, Andrus Adamchik <andru..bjectstyle.org> wrote:
    >> > > >> >> Hi Filip,
    >> > > >> >>
    >> > > >> >> > <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"/>
    >> > > >> >>
    >> > > >> >> The way relationships above are mapped you'll be getting
    >> > > >> GRANDchildren and GRANDparents. Is this really what you want?
    >> The query you quote seems correct (for grandchildren). What I
    >> mean is that
    >> > > >> >>
    >> > > >> >>
    >> > > >> >> > 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]
    >> > > >> >>
    >> > > >> >> is a short form for
    >> > > >> >>
    >> > > >> >> SELECT t0.description, t0.id, t0.parent_id
    >> > > >> >> FROM dbo.IMV_locations t0, dbo.IMV_locations t1,
    >> dbo.IMV_locations
    >> > > >> t2 WHERE t0.parent_id = t1.id AND t1.parent_id = t2.id AND
    >> t2.id > > > >> ? [bind: 1]
    >> > > >> >>
    >> > > >> >> (see an extra join)... If you need direct children, then you
    >> need
    >> > > >> to remove the last component in the obj-relationship path. The
    >> resulting mapping should look like this:
    >> > > >> >>
    >> > > >> >>
    >> > > >> >> <obj-relationship name="children" source="Location"
    >> > > >> target="Location" deleteRule="Cascade"
    >> > > >> >> db-relationship-path="rel_children"/>
    >> > > >> >>
    >> > > >> >> <obj-relationship name="parent" source="Location"
    >> target="Location"
    >> > > >> db-relationship-path="rel_parent"/>
    >> > > >> >>
    >> > > >> >> I hope I understood your requirements correctly...
    >> > > >> >>
    >> > > >> >> Andrus
    >> > > >> >>
    >> > > >> >>
    >> > > >> >
    >> > > >> >
    >> > > >> > --
    >> > > >> > Cell : 403.461.7895
    >> > > >> > Work: 403.770.1534
    >> > > >> > MSN: fbala..otmail.com
    >> > > >>
    >> > > >>
    >> > > >
    >> > > >
    >> > > > --
    >> > > > Cell : 403.461.7895
    >> > > > Work: 403.770.1534
    >> > > > MSN: fbala..otmail.com
    >> > >
    >> > >
    >> >
    >> > --
    >> > Cell : 403.461.7895
    >> > Work: 403.770.1534
    >> > MSN: fbala..otmail.com
    >> >
    >>
    >> --
    >> 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 : Wed Apr 27 2005 - 18:34:55 EDT