q.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
q.setCacheGroups("X");
List paints = context.performQuery(q);
// fetch P1 separately from cached query
Painting p1 = Cayenne.objectForPK(context, Painting.class, 33001);
Painting p2 = (Painting) paints.get(0);
Artist a1 = p2.getToArtist();
assertSame(a1, p1.getToArtist());
assertNotNull(context
.getParentDataDomain()
.getSharedSnapshotCache()
.getCachedSnapshot(p1.getObjectId()));
assertNotNull(context
.getParentDataDomain()
.getSharedSnapshotCache()
.getCachedSnapshot(p2.getObjectId()));
createTestData("testRefreshCollectionToOneUpdate");
RefreshQuery refresh = new RefreshQuery(q);
context.performQuery(refresh);
assertNotNull(context
.getParentDataDomain()
.getSharedSnapshotCache()
.getCachedSnapshot(p1.getObjectId()));
// probably refreshed eagerly
assertNotNull(context
.getParentDataDomain()
.getSharedSnapshotCache()
.getCachedSnapshot(p2.getObjectId()));
assertEquals(PersistenceState.COMMITTED, p1.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, p2.getPersistenceState());
assertSame(a1, p1.getToArtist());
assertNotSame(a1, p2.getToArtist());
assertEquals("c", p1.getToArtist().getArtistName());
assertEquals("b", p2.getToArtist().getArtistName());
}