merging relationships

From: Marcin Skladaniec (marci..sh.com.au)
Date: Thu Jan 17 2008 - 01:28:26 EST

  • Next message: Michael Gentry: "Re: Enum best practices"

    Hello

    I have encountered an exception when trying to merge relationships
    using this code :

    Artist source;
    Artist destination;
    while (source.getPaintings().size() > 0) {
            Object value = source. getPaintings().get(0);

            source.removeFromPaintings(value);
            destination.addToPaintings(value);
    }

    This code works for one-to-many relationships, no surprise. For the
    many-to-many relationships with intermediate table with compound pk
    the result is, that upon commit an error message comes up:

    The statement was aborted because it would have caused a duplicate key
    value in a unique or primary key constraint or unique index identified
    by 'SQL071114101016080' defined on
    'ARTIST_PAINTING'.java.sql.SQLException: The statement was aborted
    because it would have caused a duplicate key value in a unique or
    primary key constraint or unique index identified by
    'SQL071114101016080' defined on 'ARTIST_PAINTING'

    It is a perfectly valid error message, and we have avoided it already,
    but shouldn't cayenne resolve this internally and prevent creating
    double relationship ?

    With regards
    Marcin



    This archive was generated by hypermail 2.0.0 : Thu Jan 17 2008 - 01:29:30 EST