Re: Can a relationship return null?

From: Todd O'Bryan (toddobrya..ac.com)
Date: Sun Dec 12 2004 - 00:34:20 EST

  • Next message: Todd O'Bryan: "Hollow State in Tapestry app"

    Never mind!

    Here's what I did...I wrote a work-around method to grab each
    relationship separately and add the resulting objects to a HashSet
    which I then returned as a List. It worked.

    Then I got Andrus's email, so I commented out my work-around to see
    what the SQL was in the logger. And the Cayenne-created relationship
    worked. And I restarted my webapp about 4 times. And I don't know what
    I did between when it was returning null (which it was really doing...I
    tested it in a main method in addition to in my webapp) and what it's
    doing now, but it seems to be working.

    Sorry about the false alarm,
    Todd

    On Dec 12, 2004, at 12:15 AM, Andrus Adamchik wrote:

    > Todd,
    >
    >>> Should a relationship *ever* return null, or should it just return
    >>> an empty List if there's nothing in it?
    >
    > "To-many" - never. An empty list should be returned.
    >
    > Now back to your mapping... The only thing that is special about
    > "getTeacherForums" is that the relationship is flattened... Still it
    > is to-many, so it should be an empty list. So unless someone else
    > spots the problem in the mapping, I'd say we should investigate this.
    >
    > Could you open a bug report, so that it doesn't get lost? Please
    > attach any SQL run for the query to resolve the root User and also SQL
    > for getTeacherForums() call (if any is generated at all). This should
    > help to track it down.
    >
    > Andrus
    >
    > On Dec 11, 2004, at 11:53 PM, Todd O'Bryan wrote:
    >
    >> Whoops. Before I decided to send the xml's to the list, I was
    >> simplifying a bit. It's actually getTeacherSections() that I can call
    >> on User which works, and it's getTeacherForums() that doesn't. Sorry
    >> about any confusion.
    >>
    >> Todd
    >>
    >> On Dec 11, 2004, at 11:46 PM, Todd O'Bryan wrote:
    >>
    >>> I have a rather convoluted relationship...
    >>>
    >>> A User maps to several Section objects, and each of these maps to
    >>> several Forum objects. I created a forums relationship on User which
    >>> is a chain from User to Section to a bridge table of Section and
    >>> Forum ID's and then to Forum.
    >>>
    >>> When I call getSections() on User, it works fine.
    >>> When I call getForums() on Section, it works fine.
    >>> When I call getForums() on User, it returns null.
    >>>
    >>> Should a relationship *ever* return null, or should it just return
    >>> an empty List if there's nothing in it?
    >>>
    >>> Todd
    >>>
    >>> P.S. Each of the three object entities is in a different
    >>> DataMap...don't know if that makes a difference. I've also attached
    >>> my xml files. Hopefully they'll make it to the list.
    >>> <cayenne.xml><Courses.map.xml><Forums.map.xml><Users.map.xml>
    >>>
    >>>
    >>
    >>
    >



    This archive was generated by hypermail 2.0.0 : Sun Dec 12 2004 - 00:34:27 EST