Re: Behavior of "remove(object)" on ToManyList

From: Craig L Russell (Craig.Russel..un.COM)
Date: Wed May 30 2007 - 08:15:24 EDT

  • Next message: Kevin Menard: "RE: Behavior of "remove(object)" on ToManyList"

    On May 29, 2007, at 8:20 PM, Kevin Menard wrote:

    >> -----Original Message-----
    >> From: Andrus Adamchik [mailto:andru..bjectstyle.org]
    >> Sent: Thursday, May 24, 2007 5:52 AM
    >> To: use..ayenne.apache.org
    >> Subject: Re: Behavior of "remove(object)" on ToManyList
    >>
    >> Hi Alex,
    >>
    >> Well, actually one of Cayenne responsibilities is maintaining
    >> consistent object graph. To-many lists are a part of that
    >> object graph. So if you want to remove an object from the
    >> list for presentation reasons, but keep the relationship
    >> intact, the only right way is to clone the list and remove
    >> items from the clone. I.e.:
    >>
    >> List centers = new ArrayList(getSelectedCountry().getCenters());
    >
    > Perhaps it would make sense if the relationships return unmodifiable
    > Lists then? It seems to me like it could clear up this whole class of
    > problems.

    ... and create its own set of problems. The data in memory is a
    working copy of what you expect the database to look like after you
    commit the transaction. And a very natural way of changing the data
    model is to simply change the collection that represents the
    relationship.

    If you made the collection read-only, then the only way to change the
    contents would be to make a working copy of the read-only collection,
    change it, and then replace the collection field in the domain
    object. So you're just trading off one inconvenience for another.

    Both JDO and JPA return read-write collections and allow you to
    modify the contents with the intent of updating the database with the
    changes...

    Craig
    >
    > --
    > Kevin

    Craig Russell
    Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
    408 276-5638 mailto:Craig.Russel..un.com
    P.S. A good JDO? O, Gasp!





    This archive was generated by hypermail 2.0.0 : Wed May 30 2007 - 08:16:10 EDT