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
Hi,

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.

Cheers,

Charles


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

        tx.begin();
        PersistenceBroker broker = tx.getBroker();

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

        tx.flush();

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

        /*** Charles : Start ***/
        // Let's flush, change the name and flush again
        tx.flush();
        obj.setName("testTransactionFlushCHANGED");
        tx.flush();
        //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());
        assertFalse(it.hasNext());
        /*** Charles : End ***/

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

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

        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


Mime
View raw message