SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
Set targets = o1.getTargets();
assertEquals(3, targets.size());
SetToManyTarget target = Cayenne.objectForPK(
o1.getObjectContext(),
SetToManyTarget.class,
2);
o1.removeFromTargets(target);
assertEquals(2, targets.size());
assertFalse(o1.getTargets().contains(target));
assertNull(target.getSetToMany());
o1.getObjectContext().commitChanges();
o1.getObjectContext().performGenericQuery(new RefreshQuery());
assertEquals(2, o1.getTargets().size());