Skip to content

Commit c03e3a0

Browse files
committed
DATAMONGO-1617 - Reinstantiate version property initialization before BeforeConvertEvent publication.
Related pull request: #443.
1 parent 506b770 commit c03e3a0

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
@@ -766,7 +766,7 @@ public long count(final Query query, String collectionName) {
766766
public long count(Query query, Class<?> entityClass, String collectionName) {
767767

768768
Assert.hasText(collectionName, "Collection name must not be null or empty!");
769-
769+
770770
final DBObject dbObject = query == null ? null
771771
: queryMapper.getMappedObject(query.getQueryObject(),
772772
entityClass == null ? null : mappingContext.getPersistentEntity(entityClass));
@@ -845,11 +845,10 @@ private WriteConcern potentiallyForceAcknowledgedWrite(WriteConcern wc) {
845845

846846
protected <T> void doInsert(String collectionName, T objectToSave, MongoWriter<T> writer) {
847847

848+
initializeVersionProperty(objectToSave);
848849
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
849850
assertUpdateableIdIfNotSet(objectToSave);
850851

851-
initializeVersionProperty(objectToSave);
852-
853852
DBObject dbDoc = toDbObject(objectToSave, writer);
854853

855854
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
@@ -939,12 +938,13 @@ protected <T> void doInsertBatch(String collectionName, Collection<? extends T>
939938
Assert.notNull(writer, "MongoWriter must not be null!");
940939

941940
List<DBObject> dbObjectList = new ArrayList<DBObject>();
941+
942942
for (T o : batchToSave) {
943943

944944
initializeVersionProperty(o);
945-
BasicDBObject dbDoc = new BasicDBObject();
946-
947945
maybeEmitEvent(new BeforeConvertEvent<T>(o, collectionName));
946+
947+
BasicDBObject dbDoc = new BasicDBObject();
948948
writer.write(o, dbDoc);
949949

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

0 commit comments

Comments
 (0)