Skip to content

Commit 7a32d40

Browse files
committed
DATAMONGO-1617 - Reinstantiate version property initialization before BeforeConvertEvent publication.
Related pull request: #443.
1 parent 6593fef commit 7a32d40

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ public long count(final Query query, String collectionName) {
750750
public long count(Query query, Class<?> entityClass, String collectionName) {
751751

752752
Assert.hasText(collectionName, "Collection name must not be null or empty!");
753-
753+
754754
final DBObject dbObject = query == null ? null
755755
: queryMapper.getMappedObject(query.getQueryObject(),
756756
entityClass == null ? null : mappingContext.getPersistentEntity(entityClass));
@@ -829,11 +829,10 @@ private WriteConcern potentiallyForceAcknowledgedWrite(WriteConcern wc) {
829829

830830
protected <T> void doInsert(String collectionName, T objectToSave, MongoWriter<T> writer) {
831831

832+
initializeVersionProperty(objectToSave);
832833
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
833834
assertUpdateableIdIfNotSet(objectToSave);
834835

835-
initializeVersionProperty(objectToSave);
836-
837836
DBObject dbDoc = toDbObject(objectToSave, writer);
838837

839838
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
@@ -923,12 +922,13 @@ protected <T> void doInsertBatch(String collectionName, Collection<? extends T>
923922
Assert.notNull(writer, "MongoWriter must not be null!");
924923

925924
List<DBObject> dbObjectList = new ArrayList<DBObject>();
925+
926926
for (T o : batchToSave) {
927927

928928
initializeVersionProperty(o);
929-
BasicDBObject dbDoc = new BasicDBObject();
930-
931929
maybeEmitEvent(new BeforeConvertEvent<T>(o, collectionName));
930+
931+
BasicDBObject dbDoc = new BasicDBObject();
932932
writer.write(o, dbDoc);
933933

934934
maybeEmitEvent(new BeforeSaveEvent<T>(o, dbDoc, collectionName));

0 commit comments

Comments
 (0)