Search in sources :

Example 6 with SetToMany

use of org.apache.cayenne.testdo.relationships_set_to_many.SetToMany in project cayenne by apache.

the class CDOSetRelationshipIT method testAddToManyViaReverse.

@Test
public void testAddToManyViaReverse() throws Exception {
    createTestDataSet();
    SetToMany o1 = Cayenne.objectForPK(context, SetToMany.class, 1);
    Set targets = o1.getTargets();
    assertNotNull(targets);
    assertEquals(3, targets.size());
    SetToManyTarget newTarget = o1.getObjectContext().newObject(SetToManyTarget.class);
    newTarget.setSetToMany(o1);
    assertEquals(4, targets.size());
    assertTrue(o1.getTargets().contains(newTarget));
    assertSame(o1, newTarget.getSetToMany());
    o1.getObjectContext().commitChanges();
    o1.getObjectContext().performGenericQuery(new RefreshQuery());
    assertEquals(4, o1.getTargets().size());
}
Also used : Set(java.util.Set) RefreshQuery(org.apache.cayenne.query.RefreshQuery) SetToMany(org.apache.cayenne.testdo.relationships_set_to_many.SetToMany) SetToManyTarget(org.apache.cayenne.testdo.relationships_set_to_many.SetToManyTarget) Test(org.junit.Test)

Aggregations

Set (java.util.Set)6 SetToMany (org.apache.cayenne.testdo.relationships_set_to_many.SetToMany)6 Test (org.junit.Test)6 RefreshQuery (org.apache.cayenne.query.RefreshQuery)3 SetToManyTarget (org.apache.cayenne.testdo.relationships_set_to_many.SetToManyTarget)3 SelectQuery (org.apache.cayenne.query.SelectQuery)1 MapToMany (org.apache.cayenne.testdo.map_to_many.MapToMany)1