Re: [jira] Created: (CAY-1000) Duplicate items in list.

From: Kevin Menard (kmenar..ervprise.com)
Date: Wed Mar 05 2008 - 12:10:48 EST

  • Next message: Mike Kienenberger: "Re: [jira] Created: (CAY-1000) Duplicate items in list."

    On 3/5/08 11:52 AM, "Andrus Adamchik" <andru..bjectstyle.org> wrote:

    > Why is that a problem? The cases where duplicates could occur should
    > be expected by the user. Those are well-defined cases in the
    > application, not some obscure side effects of using Cayenne. E.g. I
    > always do that, and don't think this is a big deal:
    >
    > if(!user.getRoles().contains(role)) {
    > user.addToRoles(role);
    > }
    >
    > That's no different from List.add(..) logically.

    Yes, but a list is supposed to be a materialization of the persisted data.
    That the two can be knocked out of whack so trivially seems problematic to
    me. Anything involving a count/size operation can't be taken for granted.

    >
    >> I have yet to map a relationship as a Set. Does the set
    >> implementation used preserve iteration order?
    >
    > No, it is a HashSet.

    This makes it a non-starter then. A LinkedHashSet would meet the
    requirements, but I'm afraid those that don't care about iteration order
    will be upset at the performance hit.

    >> If so, I'd advocate this being the default rather than List. Then, if
    >> someone is worried about performance or random access, he can
    >> explicitly
    >> choose the List.
    >
    > -1. The performance impact will be huge.

    It would only be so for additions. Cayenne should be able to build up its
    internal representation just as for a List and return to the user with
    minimal overhead.
     
    >> Otherwise, data integrity is the default.
    >
    > Data integrity is not compromised. Everything that is saved to the DB
    > is correct.

    True. But I'm using Cayenne so that I don't access the DB directly.
    According to the list I'm getting from Cayenne, there are duplicates.

    I guess I'm having a little difficulty coming to terms with this, because I
    had argued the other way previously. I.e., that the list should not be a
    write-through to the backing store. So, a list is really just a snapshot
    copy. List removals would not cause object deletions. That was generally
    vetoed. Now, I'm trying to argue that if the list is going to match the
    backing store, it should always do so and the list addition shouldn't be a
    local operation. There's a disjoin here that's slightly unsettling. It's
    as if the user is just expected to know rules about how Cayenne is going to
    work with that list, rather than be able to treat it as just a list or as a
    view of the backing store. Hopefully that helps clarify my concern a bit
    more.

    -- 
    Kevin
    



    This archive was generated by hypermail 2.0.0 : Wed Mar 05 2008 - 12:11:21 EST