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

From: Kevin Menard (JIRA) ("Kevin)
Date: Wed Mar 05 2008 - 11:03:16 EST

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

        [ https://issues.apache.org/cayenne/browse/CAY-1000?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12766#action_12766 ]

    Kevin Menard commented on CAY-1000:
    -----------------------------------

    Further showing the problem:

    public void testDuplicateAdd() {
            Artist artist = (Artist) ctxt.newObject("Artist");
            artist.setArtistName("a name");
            assertTrue(artist.getPaintingArray().isEmpty());

            // Add a single painting to the artist.
            Painting painting = (Painting) ctxt.newObject("Painting");
            painting.setPaintingTitle("a painting");
            artist.addToPaintingArray(painting);
            assertEquals(1, artist.getPaintingArray().size());

            // Now add the exact same painting. Cayenne should detect the duplicate and not actually add it.
            artist.addToPaintingArray(painting);
            assertEquals(1, artist.getPaintingArray().size());

            ctxt.commitChanges();

            Artist doppelganger = DataObjectUtils.objectForPK(createDataContext(), Artist.class, DataObjectUtils.intPKForObject(artist));
            assertEquals(1, doppelganger.getPaintingArray().size());
        }

    In this case, another context retrieves the same artist. That artist's painting list will be correctly of size 1, whereas the original artist is incorrectly of size 2. They both represent exactly the same data.

    > Duplicate items in list.
    > ------------------------
    >
    > Key: CAY-1000
    > URL: https://issues.apache.org/cayenne/browse/CAY-1000
    > Project: Cayenne
    > Issue Type: Bug
    > Components: Cayenne Core Library
    > Affects Versions: 1.2 [STABLE], 2.0 [STABLE], 3.0
    > Reporter: Kevin Menard
    > Assignee: Kevin Menard
    >
    > According to the documentation on relationships (http://cayenne.apache.org/doc/relationships.html):
    > "Considering that Cayenne Lists are internally managed as ordered Sets, and are not allowed to contain the same object more than once, you may want to avoid modeling relationships as Sets at all, unless the object public interface requirements warrant that."
    > However, it is fairly trivial to show that a relationship mapped as a List can hold a duplicate. For example, the following test will fail:
    > public void testDuplicateAdd() {
    > Artist artist = (Artist) ctxt.newObject("Artist");
    > artist.setArtistName("a name");
    > assertTrue(artist.getPaintingArray().isEmpty());
    > // Add a single painting to the artist.
    > Painting painting = (Painting) ctxt.newObject("Painting");
    > painting.setPaintingTitle("a painting");
    > artist.addToPaintingArray(painting);
    > assertEquals(1, artist.getPaintingArray().size());
    > // Now add the exact same painting. Cayenne should detect the duplicate and not actually add it.
    > artist.addToPaintingArray(painting);
    > assertEquals(1, artist.getPaintingArray().size());
    > }
    > The last assertion fails because the array size will actually be 2.

    -- 
    This message is automatically generated by JIRA.
    -
    You can reply to this email to add a comment to the issue online.
    



    This archive was generated by hypermail 2.0.0 : Wed Mar 05 2008 - 11:04:29 EST