public void testRollbackRelationshipModification() {
String artistName = "relationshipModArtist";
String paintingTitle = "relationshipTestPainting";
Artist artist = (Artist) context.newObject("Artist");
artist.setArtistName(artistName);
Painting painting = (Painting) context.newObject("Painting");
painting.setPaintingTitle(paintingTitle);
painting.setToArtist(artist);
context.commitChanges();
painting.setToArtist(null);
assertEquals(0, artist.getPaintingArray().size());
context.rollbackChanges();
assertTrue(((ValueHolder) artist.getPaintingArray()).isFault());
assertEquals(1, artist.getPaintingArray().size());
assertEquals(artist, painting.getToArtist());
// Check that the reverse relationship was handled
assertEquals(1, artist.getPaintingArray().size());
context.commitChanges();
DataContext freshContext = createDataContext();
SelectQuery query = new SelectQuery(Painting.class);
query.setQualifier(ExpressionFactory.matchExp("paintingTitle", paintingTitle));
List queryResults = freshContext.performQuery(query);
assertEquals(1, queryResults.size());
Painting queriedPainting = (Painting) queryResults.get(0);
// NB: This is an easier comparison than manually fetching artist
assertEquals(artistName, queriedPainting.getToArtist().getArtistName());
}