Parent to Grandchild Relationships

From: dan17..elus.net
Date: Wed Jun 30 2004 - 12:25:47 EDT

  • Next message: Elia Morling: "Re: Working with Transient Objects"

    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 : Wed Jun 30 2004 - 12:25:48 EDT