You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Dzmitry Kazimirchyk (JIRA)" <ji...@apache.org> on 2014/02/12 18:56:19 UTC
[jira] [Created] (CAY-1898) Reordering of database operations
causes violation of unique constraint
Dzmitry Kazimirchyk created CAY-1898:
----------------------------------------
Summary: Reordering of database operations causes violation of unique constraint
Key: CAY-1898
URL: https://issues.apache.org/jira/browse/CAY-1898
Project: Cayenne
Issue Type: Bug
Components: Core Library
Affects Versions: 3.2M1
Reporter: Dzmitry Kazimirchyk
Let's say we have many-to-many junction table ArtistGallery with unique constraint for artistId and galleryId defined. Consider following code sequence:
ArtistGallery ag1 = context.newObject(ArtistGallery.class);
ag1.setToArtist(artist1);
ag1.setToGallery(gallery1);
context.commitChanges();
context.deleteObjects(ag1);
ArtistGallery ag2 = context.newObject(ArtistGallery.class);
ag2.setToArtist(artist1);
ag2.setToGallery(gallery1);
context.commitChanges();
The last commit will fail with violation of the unique constraint (artistId, galleryId). The reason of this is that Cayenne doesn't preserve original order of changes made to context and reorders database operations to be executed in the following way: inserts, updates, deletes. This makes insert which is in the end of the code sequence above to be executed before delete, therefore database will inevitably complain about constraint violation.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)