From 203d2d0187ef867d27f0a33b12b481f50311b57a Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Mon, 8 Apr 2019 08:31:36 +0200 Subject: [PATCH 1/6] DATAMONGO-2250 - Prepare issue branch. --- pom.xml | 2 +- spring-data-mongodb-benchmarks/pom.xml | 2 +- spring-data-mongodb-distribution/pom.xml | 2 +- spring-data-mongodb/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 548a846177..b8e2cf7863 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-mongodb-parent - 3.3.0-SNAPSHOT + 3.3.0.DATAMONGO-2250-SNAPSHOT pom Spring Data MongoDB diff --git a/spring-data-mongodb-benchmarks/pom.xml b/spring-data-mongodb-benchmarks/pom.xml index 0033bd11d5..2cdd2d376e 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 - 3.3.0-SNAPSHOT + 3.3.0.DATAMONGO-2250-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb-distribution/pom.xml b/spring-data-mongodb-distribution/pom.xml index f62c8dc7f4..562be3249c 100644 --- a/spring-data-mongodb-distribution/pom.xml +++ b/spring-data-mongodb-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-mongodb-parent - 3.3.0-SNAPSHOT + 3.3.0.DATAMONGO-2250-SNAPSHOT ../pom.xml diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index c1efaea420..c0eb24d741 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -11,7 +11,7 @@ org.springframework.data spring-data-mongodb-parent - 3.3.0-SNAPSHOT + 3.3.0.DATAMONGO-2250-SNAPSHOT ../pom.xml From 51a35273d3ba5e13d0985395c067152261492f10 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Thu, 4 Apr 2019 15:26:31 +0200 Subject: [PATCH 2/6] DATAMONGO-2250 - Add test case for Kotlin override properties. --- .../mongodb/core/OverridePropertyClasses.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt diff --git a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt new file mode 100644 index 0000000000..50d71a7ce2 --- /dev/null +++ b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.mongodb.core + +import com.mongodb.MongoClient +import org.junit.Test +import org.springframework.data.mongodb.repository.MongoRepository +import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory +import org.springframework.data.mongodb.test.util.Assertions.assertThat + +open class SuperType(open val field: Int) + +class SubType(val id: String, override var field: Int = 1) : SuperType(field) + +interface MyRepository : MongoRepository + +class `KotlinOverridePropertyTests` { + + val template = MongoTemplate(MongoClient(), "kotlin-tests") + + @Test // DATAMONGO-2250 + fun `Ambiguous field mapping for override val field`() { + + val repository = MongoRepositoryFactory(template).getRepository(MyRepository::class.java) + + var subType = SubType("id-1") + subType.field = 3 + + repository.save(subType) + + assertThat(repository.findById(subType.id).get().field).isEqualTo(subType.field) + } +} From 4fb6a844ddc548d1a882eda7ad77a3e6d22588d6 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Mon, 8 Apr 2019 08:41:08 +0200 Subject: [PATCH 3/6] DATAMONGO-2250 - Switch to DATACMNS-1509 makes the test pass. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b8e2cf7863..2ad5632a6f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ multi spring-data-mongodb - 2.6.0-SNAPSHOT + 2.6.0-DATACMNS-1509-SNAPSHOT 4.2.3 ${mongo} 1.19 From 19d74427f18a084b1ee79e87d9a874254957ea6a Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 19 Apr 2021 10:32:34 +0200 Subject: [PATCH 4/6] Rebase. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2ad5632a6f..06b7ae0cf5 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ multi spring-data-mongodb - 2.6.0-DATACMNS-1509-SNAPSHOT + 2.6.0.DATACMNS-1509-SNAPSHOT 4.2.3 ${mongo} 1.19 From 2bca4c9a33bf6bcac5b91def4b2435af4b4cd57e Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 19 Apr 2021 10:32:41 +0200 Subject: [PATCH 5/6] Polishing. --- .../data/mongodb/core/mapping/BasicMongoPersistentEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentEntity.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentEntity.java index 7bf8214aeb..0a555a7aa8 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentEntity.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentEntity.java @@ -353,7 +353,7 @@ private void assertUniqueness(MongoPersistentProperty property) { if (existingProperty != null) { throw new MappingException( - String.format(AMBIGUOUS_FIELD_MAPPING, property.toString(), existingProperty.toString(), fieldName)); + String.format(AMBIGUOUS_FIELD_MAPPING, property, existingProperty, fieldName)); } properties.put(fieldName, property); From ecb35886f9f2327dc763e3a8cf4302f6388d1fc5 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 19 Apr 2021 10:32:53 +0200 Subject: [PATCH 6/6] Update test to work with Kotlin override properties. --- .../mongodb/core/OverridePropertyClasses.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt index 50d71a7ce2..824fb5131d 100644 --- a/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt +++ b/spring-data-mongodb/src/test/kotlin/org/springframework/data/mongodb/core/OverridePropertyClasses.kt @@ -15,29 +15,38 @@ */ package org.springframework.data.mongodb.core -import com.mongodb.MongoClient +import com.mongodb.client.MongoClients import org.junit.Test +import org.springframework.data.mongodb.core.mapping.Field import org.springframework.data.mongodb.repository.MongoRepository import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory import org.springframework.data.mongodb.test.util.Assertions.assertThat -open class SuperType(open val field: Int) +open class SuperType(open var field: Int) -class SubType(val id: String, override var field: Int = 1) : SuperType(field) +class SubType(val id: String, @Field("foo") override var field: Int = 1) : + SuperType(field) { + + fun setFields(v: Int) { + field = v + super.field = v + } +} interface MyRepository : MongoRepository class `KotlinOverridePropertyTests` { - val template = MongoTemplate(MongoClient(), "kotlin-tests") + val template = MongoTemplate(MongoClients.create(), "kotlin-tests") @Test // DATAMONGO-2250 fun `Ambiguous field mapping for override val field`() { - val repository = MongoRepositoryFactory(template).getRepository(MyRepository::class.java) + val repository = + MongoRepositoryFactory(template).getRepository(MyRepository::class.java) var subType = SubType("id-1") - subType.field = 3 + subType.setFields(3) repository.save(subType)