Transaction tx = odmg.newTransaction();
tx.begin();
//create a TestClassBProxy and persist it
//so that when loading it again we will
//get a dynamic proxy object
TestClassBProxy b = new TestClassBProxy();
database.makePersistent(b);
tx.commit();
//reload the object created in the previous step
tx = odmg.newTransaction();
tx.begin();
OQLQuery query = odmg.newOQLQuery();
query.create("select bproxies from " + TestClassBProxy.class.getName() +
" where oid = $1");
query.bind(b.getOid());
List bList = (List) query.execute();
assertEquals(1, bList.size());
TestClassBProxyI bI = (TestClassBProxyI) bList.get(0);
//bI should now be a dynamic proxy
assertTrue(ProxyHelper.isProxy(bI));
TestClassAWithBProxy a = new TestClassAWithBProxy();
a.setBProxy(bI);
tx.lock(a, Transaction.WRITE);
tx.commit();
//on commit the foreign key in "a" should have been set to
//bOid
String aBOid = a.getBoid();
assertEquals("foreign key should match", b.getOid(), aBOid);
} catch(ODMGException ex) {
fail("ODMGException" + ex);
}
}