Issue Details (XML | Word | Printable)

Key: NUCCORE-500
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Testcase Required Testcase Required
Assignee: Unassigned
Reporter: Sudipta
Votes: 0
Watchers: 0

If you were logged in you would be able to see more operations.
DataNucleus Core

The version attribute is not getting reset on rollback

Created: 30/Mar/10 10:26 PM   Updated: 26/Apr/10 03:37 PM   Resolved: 13/Apr/10 01:31 PM
Component/s: MetaData, Transactions
Affects Version/s: 2.0.2
Fix Version/s: 2.0.4, 2.1.0.m2

 Description  « Hide
I have the following piece of code:

        PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
        ClassA a = new ClassA();
        pm.makePersistent(a); //Persist a

        a.setValue(6); //Update the value of a
        //Now run a query, this will flush the change to a to the database
        //since I have datanucleus.query.flushBeforeExecution=true in
        Query query = pm.newQuery(ClassB.class);
        query.declareParameters("String match");
        HashMap params = new HashMap();
params.put("match", ".*Device.*");
        System.out.println("Query: " + query);
Collection result = (Collection)query.executeWithMap(params);
Iterator iter = result.iterator();
while (iter.hasNext()) {
ClassB c = (ClassB);
            System.out.println("retrieved " + c.getName());
        tx.rollback(); //Now Rollback the transaction

        a.setValue(7); //Now again update the value of a
        tx.commit(); //This commit will cause an update to the database and fails with OptimisticVerificationException

When I run the above code it fails with the following exception:
javax.jdo.JDOOptimisticVerificationException: Object "org.datanucleus.test.ClassA@13c6641" (id="66[OID]org.datanucleus.test.ClassRealm") has been changed in the datastore since your last read. Your transaction is using version "3" but this doesnt exist in the datastore now
FailedObject:name: Rollback, value=5
at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(
at org.datanucleus.jdo.JDOTransaction.commit(

The update SQL from the log file when the exception is throws:
UPDATE class_a SET val=<7>, jdo_version=<3> WHERE class_a_id=<66> AND jdo_version=<2>

Notice that it is trying to set 3 for jdo_version and in the where it is using 2.

The table corresponding to ClassA id class_a.
jdo_version is the name of the version column.

The version value of the object "a" should get reset to 1 after the rollback but it remains at 2.

Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 13/Apr/10 01:31 PM
Likely fixed in SVN trunk and branches/2.0 but since no testcase was provided that is anybodys guess. If problem persists raise a new issue *with* a testcase the demonstrates something.