TransactionExt tx = (TransactionExt) odmg.newTransaction();
tx.begin();
PersistenceBroker broker = tx.getBroker();
ODMGZoo obj = new ODMGZoo();
obj.setName(name);
tx.lock(obj, Transaction.WRITE);
tx.flush();
// System.err.println("First flush call, insert new object");
// PB to query
Criteria crit = new Criteria();
crit.addEqualTo("name", obj.getName());
QueryByCriteria query = QueryFactory.newQuery(ODMGZoo.class, crit);
// we flushed all objects, thus we should found object in DB/cache
Iterator it = broker.getIteratorByQuery(query);
assertTrue(it.hasNext());
ODMGZoo other = (ODMGZoo) it.next();
assertNotNull(other);
assertEquals(obj.getZooId(), other.getZooId());
assertEquals(obj.getName(), other.getName());
assertFalse(it.hasNext());
/*** Charles : Start ***/
// Let's flush, change the name and flush again
tx.flush();
// System.err.println("Second flush call, nothing to do");
obj.setName("updated_" + name);
tx.flush();
// System.err.println("Third flush call, update");
OQLQuery q = odmg.newOQLQuery();
q.create("select zoos from " + ODMGZoo.class.getName() + " where name like $1");
q.bind("updated_" + name);
//Redo the query - we should find the object again
it = ((Collection) q.execute()).iterator();
assertTrue(it.hasNext());
other = (ODMGZoo) it.next();
assertNotNull(other);
assertEquals(obj.getZooId(), other.getZooId());
assertEquals(obj.getName(), other.getName());
assertFalse(it.hasNext());
/*** Charles : End ***/
// now we abort tx, so all flushed objects shouldn't be found
// in further queries