Search in sources :

Example 11 with CompoundPkTestEntity

use of org.apache.cayenne.testdo.compound.CompoundPkTestEntity in project cayenne by apache.

the class DataContextCompoundRelIT method testInsert.

@Test
public void testInsert() {
    CompoundPkTestEntity master = context.newObject(CompoundPkTestEntity.class);
    CompoundFkTestEntity detail = context.newObject(CompoundFkTestEntity.class);
    master.addToCompoundFkArray(detail);
    master.setName("m1");
    master.setKey1("key11");
    master.setKey2("key21");
    detail.setName("d1");
    context.commitChanges();
    context.invalidateObjects(master, detail);
    SelectQuery q = new SelectQuery(CompoundPkTestEntity.class);
    List<?> objs = context1.performQuery(q);
    assertEquals(1, objs.size());
    master = (CompoundPkTestEntity) objs.get(0);
    assertEquals("m1", master.getName());
    List<?> details = master.getCompoundFkArray();
    assertEquals(1, details.size());
    detail = (CompoundFkTestEntity) details.get(0);
    assertEquals("d1", detail.getName());
}
Also used : CompoundPkTestEntity(org.apache.cayenne.testdo.compound.CompoundPkTestEntity) SelectQuery(org.apache.cayenne.query.SelectQuery) CompoundFkTestEntity(org.apache.cayenne.testdo.compound.CompoundFkTestEntity) Test(org.junit.Test)

Aggregations

CompoundPkTestEntity (org.apache.cayenne.testdo.compound.CompoundPkTestEntity)11 Test (org.junit.Test)11 CompoundFkTestEntity (org.apache.cayenne.testdo.compound.CompoundFkTestEntity)8 HashMap (java.util.HashMap)6 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)4 SelectQuery (org.apache.cayenne.query.SelectQuery)3 Expression (org.apache.cayenne.exp.Expression)2 ObjectIdQuery (org.apache.cayenne.query.ObjectIdQuery)2 SQLTemplate (org.apache.cayenne.query.SQLTemplate)2 QueryResponse (org.apache.cayenne.QueryResponse)1