Feb 25th, 2013, 11:28 AM
Mongodb: suspected bugs in @Version management
I'm looking into the @Version management in spring-data-mongo 1.2.0.RELEASE.
The design is great, convenient and transparent, but I suspect some bugs:
1) When a @Version'ed object is updated, the "collectionName" parameter is ignored, and instead the default collection is used (based on class name).
This happens in MongoTemplate.doSaveVersioned():
- if version is not null, it calls updateFirst(query, update, objectToSave.getClass());
- while it should call doUpdate(collectionName, query, update, objectToSave.getClass(), false, false);
2) Type mismatch in MongoTemplate.initializeVersionProperty():
It sets version to '0', while it should be long: '0L'
3) Consideration for a "race" of two inserts":
Assume "user1" has successfully inserted a new DBObject.
Then another "user2" tries to insert a new DBObject with the same ID (and version=null as typical for inserts).
I'd expect user2 to fail, but instead he performs an update. That's in MongoTemplate.doSaveVersioned():
if version is null, it calls doSave(...). I believe it should call doInsert(...) which would properly fail on 'duplicate id'.
But admittedly it's a non-trivial scenario and I'd appreciate more opinions on it.
Thanks very much
Feb 26th, 2013, 04:45 AM
Feb 27th, 2013, 02:30 AM
Thanks very much, plus extra thanks for the quick response.