Re: Parent to Grandchild Relationships

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jul 01 2004 - 13:37:55 EDT

  • Next message: Andrus Adamchik: "Re: Many To Many relations: how to?"

    Hi Dan,

    So you are saying that a flattened to-many relationship doesn't work?
    Could you open a bug report including the part of the DataMap showing how
    the flattened relationship works, version of Cayenne, and SQL generated
    when you are trying to read the relationship. Here is the link to the bug
    tracker: http://objectstyle.org/cayenne/bugs-features.html

    As for the alternative method that you are suggesting, it can be easily
    optimized by using an explicit SelectQuery instead of "getChildren()", and
    setting prefetching of grandchildren relationship
    (http://objectstyle.org/cayenne/userguide/perform/prefetching.html). This
    will be a good work around, but still, lets get to the core of the problem
    with flattened relationship ...

    Andrus

    ------------

    On Jun 30, 2004, at 12:25 PM, dan17..elus.net wrote:
    I have three tables:

    Table Parent:
    PARENT_ID INTEGER PK AUTOGEN
    NAME STRING

    Table Child
    CHILD_ID INTEGER PK AUTOGEN
    PARENT_ID INTEGER FK
    NAME STRING

    Table GrandChild:
    GRANDCHILD_ID INTEGER PK AUTOGEN
    CHILD_ID INTEGER FK
    NAME STRING

    When I make a relationship in the Parent object List getGrandChildren() using
    the cayenne modelar it doesn't seem to work until the objects have been
    committed.

    but if I use:

     public List getGrandChildren() {
            List result = new ArrayList();
            Iterator i = getChildren().iterator();
            while (i.hasNext()) {
                Child child = (Child) i.next();
                result.addAll(child.getGrandChildren());
            }
            return result;
        }

    It works fine.

    The second method works but it generates a lot more db queries then the first
    if the objects aren't already in memory.

    Have I missed something or is this a bug?

    - Dan



    This archive was generated by hypermail 2.0.0 : Thu Jul 01 2004 - 13:37:55 EDT