Transaction tx = odmg.newTransaction();
long currentTime = System.currentTimeMillis();
BidirectionalAssociationObjectA a = new BidirectionalAssociationObjectA();
a.setPk("A" + currentTime);
BidirectionalAssociationObjectB b = new BidirectionalAssociationObjectB();
b.setPk("B" + currentTime);
tx.begin();
db.makePersistent(a);
db.makePersistent(b);
tx.commit();
tx.begin();
tx.lock(a, Transaction.WRITE);
tx.lock(b, Transaction.WRITE);
a.setRelatedB(b);
b.setRelatedA(a);
tx.commit();
/**
* now make sure they are in db, A first, then B
*/
tx.begin();
OQLQuery query = odmg.newOQLQuery();
int i = 0;
query.create("select bidirectionalAssociationObjectA from " + BidirectionalAssociationObjectA.class.getName() + " where pk=$1");
query.bind("A"+currentTime);
ManageableCollection all = (ManageableCollection) query.execute();
java.util.Iterator it = all.ojbIterator();
while (it.hasNext())
{
i++;
a = (BidirectionalAssociationObjectA) it.next();
if (a.getRelatedB() == null)
fail("a should have had a related b");
}
if (i > 1)
fail("should have found only one bidirectionalAssociationObjectA, instead found: " + i);
query = odmg.newOQLQuery();
i = 0;
query.create("select bidirectionalAssociationObjectB from " + BidirectionalAssociationObjectB.class.getName() + " where pk=$1");
query.bind("B"+currentTime);
all = (ManageableCollection) query.execute();
it = all.ojbIterator();
while (it.hasNext())
{
i++;
b = (BidirectionalAssociationObjectB) it.next();
if (b.getRelatedA() == null)
fail("b should have had a related a");
}
if (i > 1)
fail("should have found only one bidirectionalAssociationObjectB, instead found: " + i);