OpenJPAEntityManager pm = getPM();
RuntimeTest1 b = (RuntimeTest1) pm.find(RuntimeTest1.class, _id);
assertEquals("STRING", b.getStringField());
// invalid with possible subclasses should throw immediate exception
Object invalidId = new Id(RuntimeTest1.class, -1L);
try {
pm.find(RuntimeTest1.class, invalidId);
fail("Invalid Object");
} catch (Exception e) {
}
// invalid without subclasses and without validating should return
// hollow
invalidId = new Id(RuntimeTest4.class, -1L);
try {
RuntimeTest4 a = (RuntimeTest4) pm.getReference(RuntimeTest4.class,
invalidId);
assertNotNull("invalid without subclasses and without validating "
+ "should return hollow or throw exception", a);
a.getName();
fail("Allowed access of invalid hollow instance.");
}
catch (EntityNotFoundException enfe) {
// expected
}
invalidId = new Id(RuntimeTest4.class, -3L);
assertNull(pm.find(RuntimeTest4.class, invalidId));
endEm(pm);
}