use of org.apache.cayenne.testdo.generated.GeneratedF2 in project cayenne by apache.
the class IdentityColumnsIT method testGeneratedJoinInFlattenedRelationship.
@Test
public void testGeneratedJoinInFlattenedRelationship() throws Exception {
// before saving objects, let's manually access PKGenerator to get a
// base PK value
// for comparison
DbEntity joinTableEntity = context.getEntityResolver().getDbEntity(joinTable.getTableName());
DbAttribute pkAttribute = joinTableEntity.getAttribute("ID");
Number pk = (Number) adapter.getPkGenerator().generatePk(node, pkAttribute);
GeneratedF1 f1 = context.newObject(GeneratedF1.class);
GeneratedF2 f2 = context.newObject(GeneratedF2.class);
f1.addToF2(f2);
context.commitChanges();
int id = joinTable.getInt("ID");
assertTrue(id > 0);
// base value
if (adapter.supportsGeneratedKeys()) {
assertFalse("Looks like auto-increment wasn't used for the join table. ID: " + id, id == pk.intValue() + 1);
} else {
assertEquals(id, pk.intValue() + 1);
}
}
Aggregations