clear();
OpenJPAEntityManager em = (OpenJPAEntityManager) factory
.createEntityManager();
CacheObjectA a;
CacheObjectA aparent;
try {
// we can't specify this for UserTransaction
/*
* pm.currentTransaction().setNontransactionalRead(true);
* pm.currentTransaction().setOptimistic(true);
*/
// em.setNontransactionalRead(true);
// em.setOptimistic(true);
a = new CacheObjectA(ORIG_NAME, ORIG_AGE);
aparent = new CacheObjectA(ORIG_PARENT_NAME, ORIG_PARENT_AGE);
a.setRelatedObject(aparent);
LinkedList children = new LinkedList();
children.add(a);
aparent.setRelatedCollection(children);
startTx(em);
em.persist(a);
em.persist(aparent);
oid = em.getObjectId(a);
oidwithclass = new Id(CacheObjectA.class, oid.toString());
parentOid = em.getObjectId(aparent);
endTx(em);
}
finally {
endEm(em);
}
// load an object in a separate pm before the update
// happens. This should not change, else we're in
// violation of the spec.
this.em = factory.createEntityManager();
startTx(this.em);
try {
// OpenJPAEntityManager openEm=(OpenJPAEntityManager) this.em;
this.a = (CacheObjectA) this.em.find(CacheObjectA.class, oid);
// load the parent for testCollections().
CacheObjectA rel = this.a.getRelatedObject();
rel.getRelatedCollection();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
endTx(this.em);
// endEm(this.em);
}
em = factory.createEntityManager();
try {
startTx(em);
a = (CacheObjectA) em.find(CacheObjectA.class, oid);
a.setName(NEW_NAME);
aparent = (CacheObjectA) em.find(CacheObjectA.class, parentOid);
CacheObjectA a2 = new CacheObjectA(ORIG_NAME, ORIG_AGE);
a2.setRelatedObject(aparent);
aparent.getRelatedCollection().add(a2);
em.persist(a2);
endTx(em);
assertNew(a);