DataNucleus JIRA is now in read-only mode. Raise any new issues in GitHub against the plugin that it applies to. DataNucleus JIRA will remain for the foreseeable future but will eventually be discontinued
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
Operations

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();
tx.setOptimistic(true);
        tx.begin();
        ClassA a = new ClassA();
        a.setName("Rollback");
        a.setValue(5);
        pm.makePersistent(a); //Persist a
        tx.commit();

        tx.begin();
        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 datanucleus.properties
        Query query = pm.newQuery(ClassB.class);
query.setFilter("name.matches(match)");
        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)iter.next();
            System.out.println("retrieved " + c.getName());
        }
        tx.rollback(); //Now Rollback the transaction

        tx.begin();
        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(NucleusJDOHelper.java:399)
at org.datanucleus.jdo.JDOTransaction.commit(JDOTransaction.java:116)

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.




Andy Jefferson made changes - 13/Apr/10 11:57 AM
Field Original Value New Value
Priority Major [ 3 ] Incomplete [ 6 ]
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.

Andy Jefferson made changes - 13/Apr/10 01:31 PM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 2.0.4 [ 10921 ]
Fix Version/s 2.1.0.m2 [ 10901 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 26/Apr/10 03:37 PM
Status Resolved [ 5 ] Closed [ 6 ]