DATAMONGO-1617 - Reinstantiate version property initialization before BeforeConvertEvent publication.

Related pull request: #443.
This commit is contained in:
Oliver Gierke
2017-02-28 20:05:35 +01:00
parent 6593fef803
commit 7a32d40dd0

View File

@@ -750,7 +750,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
public long count(Query query, Class<?> entityClass, String collectionName) {
Assert.hasText(collectionName, "Collection name must not be null or empty!");
final DBObject dbObject = query == null ? null
: queryMapper.getMappedObject(query.getQueryObject(),
entityClass == null ? null : mappingContext.getPersistentEntity(entityClass));
@@ -829,11 +829,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
protected <T> void doInsert(String collectionName, T objectToSave, MongoWriter<T> writer) {
initializeVersionProperty(objectToSave);
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
assertUpdateableIdIfNotSet(objectToSave);
initializeVersionProperty(objectToSave);
DBObject dbDoc = toDbObject(objectToSave, writer);
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
@@ -923,12 +922,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
Assert.notNull(writer, "MongoWriter must not be null!");
List<DBObject> dbObjectList = new ArrayList<DBObject>();
for (T o : batchToSave) {
initializeVersionProperty(o);
BasicDBObject dbDoc = new BasicDBObject();
maybeEmitEvent(new BeforeConvertEvent<T>(o, collectionName));
BasicDBObject dbDoc = new BasicDBObject();
writer.write(o, dbDoc);
maybeEmitEvent(new BeforeSaveEvent<T>(o, dbDoc, collectionName));