Search in sources :

Example 1 with CharFkTestEntity

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

the class DataContextPrefetchExtrasIT method testPrefetchToManyOnCharKey.

@Test
public void testPrefetchToManyOnCharKey() throws Exception {
    createPrefetchToManyOnCharKeyDataSet();
    SelectQuery q = new SelectQuery(CharPkTestEntity.class);
    q.addPrefetch("charFKs");
    q.addOrdering(CharPkTestEntity.OTHER_COL.asc());
    List<?> pks = context.performQuery(q);
    assertEquals(2, pks.size());
    CharPkTestEntity pk1 = (CharPkTestEntity) pks.get(0);
    assertEquals("n1", pk1.getOtherCol());
    List<?> toMany = (List<?>) pk1.readPropertyDirectly("charFKs");
    assertNotNull(toMany);
    assertFalse(((ValueHolder) toMany).isFault());
    assertEquals(3, toMany.size());
    CharFkTestEntity fk1 = (CharFkTestEntity) toMany.get(0);
    assertEquals(PersistenceState.COMMITTED, fk1.getPersistenceState());
    assertSame(pk1, fk1.getToCharPK());
}
Also used : SelectQuery(org.apache.cayenne.query.SelectQuery) CharFkTestEntity(org.apache.cayenne.testdo.compound.CharFkTestEntity) CharPkTestEntity(org.apache.cayenne.testdo.compound.CharPkTestEntity) List(java.util.List) Test(org.junit.Test)

Aggregations

List (java.util.List)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 CharFkTestEntity (org.apache.cayenne.testdo.compound.CharFkTestEntity)1 CharPkTestEntity (org.apache.cayenne.testdo.compound.CharPkTestEntity)1 Test (org.junit.Test)1