diff --git a/pom.xml b/pom.xml index 1d9b760700..b22d970222 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 1.9.0.BUILD-SNAPSHOT + 1.9.0.DATAMONGO-1401-SNAPSHOT pom Spring Data MongoDB diff --git a/spring-data-mongodb-cross-store/pom.xml b/spring-data-mongodb-cross-store/pom.xml index fd36debedd..6b98c19c95 100644 --- a/spring-data-mongodb-cross-store/pom.xml +++ b/spring-data-mongodb-cross-store/pom.xml @@ -6,7 +6,7 @@ org.springframework.data spring-data-mongodb-parent - 1.9.0.BUILD-SNAPSHOT + 1.9.0.DATAMONGO-1401-SNAPSHOT ../pom.xml @@ -48,7 +48,7 @@ org.springframework.data spring-data-mongodb - 1.9.0.BUILD-SNAPSHOT + 1.9.0.DATAMONGO-1401-SNAPSHOT diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml index 28c91bc332..8609490435 100644 --- a/spring-data-mongodb-distribution/pom.xml +++ b/spring-data-mongodb-distribution/pom.xml @@ -13,7 +13,7 @@ org.springframework.data spring-data-mongodb-parent - 1.9.0.BUILD-SNAPSHOT + 1.9.0.DATAMONGO-1401-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb-log4j/pom.xml b/spring-data-mongodb-log4j/pom.xml index dfe146ff96..26030e8372 100644 --- a/spring-data-mongodb-log4j/pom.xml +++ b/spring-data-mongodb-log4j/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 1.9.0.BUILD-SNAPSHOT + 1.9.0.DATAMONGO-1401-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index 0fcdb2f39f..b12e76d4ee 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -11,7 +11,7 @@ org.springframework.data spring-data-mongodb-parent - 1.9.0.BUILD-SNAPSHOT + 1.9.0.DATAMONGO-1401-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java index e6b9587c2a..f439254475 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import org.springframework.data.mapping.PersistentEntity; import org.springframework.data.mapping.PropertyPath; import org.springframework.data.mapping.PropertyReferenceException; +import org.springframework.data.mapping.context.InvalidPersistentPropertyPath; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.context.PersistentPropertyPath; import org.springframework.data.mapping.model.MappingException; @@ -122,10 +123,20 @@ public DBObject getMappedObject(DBObject query, MongoPersistentEntity entity) continue; } - Field field = createPropertyField(entity, key, mappingContext); - Entry entry = getMappedObjectForField(field, query.get(key)); + try { + + Field field = createPropertyField(entity, key, mappingContext); + Entry entry = getMappedObjectForField(field, query.get(key)); + result.put(entry.getKey(), entry.getValue()); + } catch (InvalidPersistentPropertyPath invalidPathException) { - result.put(entry.getKey(), entry.getValue()); + // in case the object has not already been mapped + if (!(query.get(key) instanceof DBObject)) { + throw invalidPathException; + } + + result.put(key, query.get(key)); + } } return result; diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java index 1feec65532..86ce2a08b6 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2015 the original author or authors. + * Copyright 2011-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,6 +63,7 @@ import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver; import org.springframework.data.mongodb.core.convert.LazyLoadingProxy; import org.springframework.data.mongodb.core.convert.MappingMongoConverter; +import org.springframework.data.mongodb.core.geo.GeoJsonPoint; import org.springframework.data.mongodb.core.index.Index; import org.springframework.data.mongodb.core.index.Index.Duplicates; import org.springframework.data.mongodb.core.index.IndexField; @@ -197,6 +198,7 @@ protected void cleanDb() { template.dropCollection(SomeTemplate.class); template.dropCollection(Address.class); template.dropCollection(DocumentWithCollectionOfSamples.class); + template.dropCollection(WithGeoJson.class); } @Test @@ -3143,11 +3145,30 @@ public void shouldRespectParamterValueWhenAttemptingToReuseLazyLoadedDBRefUsedIn assertThat(loaded.refToDocNotUsedInCtor, instanceOf(LazyLoadingProxy.class)); } + /** + * @see DATAMONGO-1401 + */ + @Test + public void updateShouldWorkForTypesContainingGeoJsonTypes() { + + WithGeoJson wgj = new WithGeoJson(); + wgj.id = "1"; + wgj.description = "datamongo-1401"; + wgj.point = new GeoJsonPoint(1D, 2D); + + template.save(wgj); + + wgj.description = "datamongo-1401-update"; + template.save(wgj); + + assertThat(template.findOne(query(where("id").is(wgj.id)), WithGeoJson.class).point, is(equalTo(wgj.point))); + } + static class DoucmentWithNamedIdField { @Id String someIdKey; - @Field(value = "val")// + @Field(value = "val") // String value; @Override @@ -3484,4 +3505,13 @@ public DocumentWithLazyDBrefUsedInPresistenceConstructor(Document refToDocUsedIn } + static class WithGeoJson { + + @Id String id; + @Version // + Integer version; + String description; + GeoJsonPoint point; + } + }