(OpenJPAEntityManager) currentEntityManager();
Broker broker = JPAFacadeHelper.toBroker(pm);
startTx(pm);
// register a new instance with the PM
BasicSubclassInstance basic = (BasicSubclassInstance) newInstance
(pm, BasicSubclassInstance.class);
assertTrue(ImplHelper.isManageable(basic));
basic.setStringField("foo");
pm.persist(basic);
assertTrue(broker.isNew(basic));
assertTrue(broker.isPersistent(basic));
// commit. this should cause the data to be written.
// ### should check SQL count
endTx(pm);
assertFalse(broker.isNew(basic));
OpenJPAStateManager sm = broker.getStateManager(basic);
assertNotNull(sm);
assertEquals(sm.getManagedInstance(), basic);
FieldMetaData fmd = sm.getMetaData().getField("stringField");
assertEquals("foo", sm.fetch(fmd.getIndex()));
assertTrue(sm.getLoaded().get(fmd.getIndex()));
pm.evict(basic);
assertFalse(sm.getLoaded().get(fmd.getIndex()));
// lazy loading
assertNotNull(basic.getStringField());
assertEquals("foo", sm.fetch(fmd.getIndex()));
assertEquals("foo", basic.getStringField());
assertTrue(sm.getLoaded().get(fmd.getIndex()));
startTx(pm);
basic.setStringField("bar");
assertTrue(broker.isDirty(basic));
endTx(pm);
Object oid = broker.getObjectId(basic);
assertNotNull(oid);
endEm(pm);
pm = (OpenJPAEntityManager) currentEntityManager();
basic =
(BasicSubclassInstance) pm.find(BasicSubclassInstance.class, oid);
assertEquals("bar", basic.getStringField());
startTx(pm);
pm.remove(basic);
assertTrue(JPAFacadeHelper.toBroker(pm).isDeleted(basic));
endTx(pm);