db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Anthony <charles.anth...@hpdsoftware.com>
Subject Problems with TransactionExt.flush
Date Thu, 22 Jul 2004 12:12:15 GMT

I've got a quite big (and urgent) problem with the odmg TransactionExt.flush
method. In many places in our app we 
1. lock an object to the transaction
2. we *don't* modify it, 
3. flush the tx, 
4. modify it
5. then commit. 

With CVS Head (and, I suspect, the release version), the commit does not
write the changes to the database (whereas our version from Sept last year
does). If I remove the flush, it gets written correctly.

I have modified org.apache.ojb.odmg.ODMGRollbackTest.testTransactionFlush
method to reproduce the error. The modified method follow this email.

I think (but I haven't checked) it is to do with the
ObjectEnveloper.hasChanged being set to FALSE on the flush - then not being
reset to null, so that when we commit ObjectEnveloper.hasChanged immediately
returns false instead of checking the maps.



    public void testTransactionFlush() throws Exception
        TransactionExt tx = (TransactionExt) odmg.newTransaction();

        PersistenceBroker broker = tx.getBroker();

        ODMGZoo obj = new ODMGZoo();
        tx.lock(obj, Transaction.WRITE);


        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);
        assertSame(obj, it.next());

        /*** Charles : Start ***/
        // Let's flush, change the name and flush again
        //Redo the query - we should find the object again
        crit = new Criteria();
        crit.addEqualTo("name", obj.getName());
        query = QueryFactory.newQuery(ODMGZoo.class, crit);
        // we flushed all objects, thus we should found object in DB/cache
        it = broker.getIteratorByQuery(query);
        assertTrue("Should find object",it.hasNext());
        assertSame(obj, it.next());
        /*** Charles : End ***/

        // now we abort tx, so all flushed objects shouldn't be found
        // in further queries

        tx = (TransactionExt) odmg.newTransaction();
        broker = tx.getBroker();
        QueryByIdentity query2 = new QueryByIdentity(obj);
        Object result = broker.getObjectByQuery(query2);

        assertNull("We should not find objects from aborted tx", result);



HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 

To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org

View raw message