diff --git a/pom.xml b/pom.xml
index d46bb41533..bb59e0d3a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.2.4-SNAPSHOT
+ 4.2.x-4653-SNAPSHOT
pom
Spring Data MongoDB
@@ -26,7 +26,7 @@
multi
spring-data-mongodb
- 3.2.4-SNAPSHOT
+ 3.2.4-GH-3056-SNAPSHOT
4.11.1
${mongo}
1.19
diff --git a/spring-data-mongodb-benchmarks/pom.xml b/spring-data-mongodb-benchmarks/pom.xml
index c559a29868..95b3309fae 100644
--- a/spring-data-mongodb-benchmarks/pom.xml
+++ b/spring-data-mongodb-benchmarks/pom.xml
@@ -7,7 +7,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.2.4-SNAPSHOT
+ 4.2.x-4653-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml
index bf8bc54e23..6d4f8d32db 100644
--- a/spring-data-mongodb-distribution/pom.xml
+++ b/spring-data-mongodb-distribution/pom.xml
@@ -15,7 +15,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.2.4-SNAPSHOT
+ 4.2.x-4653-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml
index f594d4f117..50533b5fcb 100644
--- a/spring-data-mongodb/pom.xml
+++ b/spring-data-mongodb/pom.xml
@@ -13,7 +13,7 @@
org.springframework.data
spring-data-mongodb-parent
- 4.2.4-SNAPSHOT
+ 4.2.x-4653-SNAPSHOT
../pom.xml
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java
index 78e0ba4eea..19aac4dd7c 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentProperty.java
@@ -23,6 +23,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
@@ -318,7 +319,7 @@ protected void validate() {
String annotatedName = getAnnotatedFieldName();
if (!ID_FIELD_NAME.equals(annotatedName)) {
- if(LOG.isWarnEnabled()) {
+ if (LOG.isWarnEnabled()) {
LOG.warn(String.format(
"Customizing field name for id property '%s.%s' is not allowed; Custom name ('%s') will not be considered",
getOwner().getName(), getName(), annotatedName));
diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentPropertyUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentPropertyUnitTests.java
index 7e00c70f04..e175275530 100644
--- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentPropertyUnitTests.java
+++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentPropertyUnitTests.java
@@ -23,14 +23,19 @@
import java.lang.annotation.Target;
import java.lang.reflect.Field;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.jmolecules.ddd.annotation.Identity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.MappingException;
@@ -39,7 +44,7 @@
import org.springframework.data.mapping.model.Property;
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
import org.springframework.data.mapping.model.SimpleTypeHolder;
-import org.springframework.data.util.ClassTypeInformation;
+import org.springframework.data.util.TypeInformation;
import org.springframework.util.ReflectionUtils;
/**
@@ -56,7 +61,7 @@ public class BasicMongoPersistentPropertyUnitTests {
@BeforeEach
void setup() {
- entity = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(Person.class));
+ entity = new BasicMongoPersistentEntity<>(TypeInformation.of(Person.class));
}
@Test
@@ -90,7 +95,7 @@ void preventsNegativeOrder() {
void usesPropertyAccessForThrowableCause() {
BasicMongoPersistentEntity entity = new BasicMongoPersistentEntity<>(
- ClassTypeInformation.from(Throwable.class));
+ TypeInformation.of(Throwable.class));
MongoPersistentProperty property = getPropertyFor(entity, "cause");
assertThat(property.usePropertyAccess()).isTrue();
@@ -99,7 +104,7 @@ void usesPropertyAccessForThrowableCause() {
@Test // DATAMONGO-607
void usesCustomFieldNamingStrategyByDefault() throws Exception {
- ClassTypeInformation type = ClassTypeInformation.from(Person.class);
+ TypeInformation type = TypeInformation.of(Person.class);
Field field = ReflectionUtils.findField(Person.class, "lastname");
MongoPersistentProperty property = new BasicMongoPersistentProperty(Property.of(type, field), entity,
@@ -116,7 +121,7 @@ void usesCustomFieldNamingStrategyByDefault() throws Exception {
@Test // DATAMONGO-607
void rejectsInvalidValueReturnedByFieldNamingStrategy() {
- ClassTypeInformation type = ClassTypeInformation.from(Person.class);
+ TypeInformation type = TypeInformation.of(Person.class);
Field field = ReflectionUtils.findField(Person.class, "lastname");
MongoPersistentProperty property = new BasicMongoPersistentProperty(Property.of(type, field), entity,
@@ -250,12 +255,32 @@ void considersJMoleculesIdentityExplicitlyAnnotatedIdentifier() {
assertThat(property.isExplicitIdProperty()).isTrue();
}
+ @ParameterizedTest // GH-4653
+ @ValueSource(strings = { "objectMap", "stringMap", "mapOfSet", "objectSet", "stringSet", "objectIterable",
+ "stringIterable", "iterableOfSet" })
+ void doesNotConsiderCollectionLikeTypesEntities(String field) {
+
+ MongoPersistentProperty property = getPropertyFor(WithCollectionAndMapTypes.class, field);
+ assertThat(property.getPersistentEntityTypeInformation()).isEmpty();
+ assertThat(property.isEntity()).isFalse();
+ }
+
+ @ParameterizedTest // GH-4653
+ @ValueSource(strings = { "mapOfSetOfComplexId", "mapKeyOfSetOfComplexId", "listOfSetOfComplexId" })
+ void doesConsiderEntityTypeInformation(String field) {
+
+ MongoPersistentProperty property = getPropertyFor(WithCollectionAndMapTypes.class, field);
+ assertThat(property.getPersistentEntityTypeInformation()).hasSize(1).map(TypeInformation::getType)
+ .contains((Class) ComplexId.class);
+ assertThat(property.isEntity()).isTrue();
+ }
+
private MongoPersistentProperty getPropertyFor(Field field) {
return getPropertyFor(entity, field);
}
private static MongoPersistentProperty getPropertyFor(Class type, String fieldname) {
- return getPropertyFor(new BasicMongoPersistentEntity<>(ClassTypeInformation.from(type)), fieldname);
+ return getPropertyFor(new BasicMongoPersistentEntity<>(TypeInformation.of(type)), fieldname);
}
private static MongoPersistentProperty getPropertyFor(MongoPersistentEntity> entity, String fieldname) {
@@ -335,12 +360,14 @@ static class DocumentWithExplicitlyRenamedIdProperty {
static class DocumentWithExplicitlyRenamedIdPropertyHavingIdAnnotation {
- @Id @org.springframework.data.mongodb.core.mapping.Field("id") String id;
+ @Id
+ @org.springframework.data.mongodb.core.mapping.Field("id") String id;
}
static class DocumentWithComposedAnnotations {
- @ComposedIdAnnotation @ComposedFieldAnnotation String myId;
+ @ComposedIdAnnotation
+ @ComposedFieldAnnotation String myId;
@ComposedFieldAnnotation(name = "myField") String myField;
}
@@ -356,7 +383,8 @@ static class DocumentWithComposedAnnotations {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Id
- static @interface ComposedIdAnnotation {}
+ static @interface ComposedIdAnnotation {
+ }
static class WithStringMongoId {
@@ -375,10 +403,28 @@ static class ComplexId {
static class WithComplexId {
- @Id @org.springframework.data.mongodb.core.mapping.Field ComplexId id;
+ @Id
+ @org.springframework.data.mongodb.core.mapping.Field ComplexId id;
}
static class WithJMoleculesIdentity {
@Identity ObjectId identifier;
}
+
+ static class WithCollectionAndMapTypes {
+
+ Map objectMap;
+ Map stringMap;
+ Map> mapOfSet;
+ HashSet