Skip to content

Commit ada7e19

Browse files
odrotbohmmp911de
authored andcommitted
Properly detect all supported identifier annotations as explicitly annotated.
We now simply delegate to AnnotationBasedPersistentProperty.isIdProperty() for the detection of annotated identifiers. The previous, manual identifier check was preventing additional identifier annotations, supported by ABP, to be considered, too. Fixes #3803.
1 parent 977e5e4 commit ada7e19

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

spring-data-mongodb/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@
317317
<scope>test</scope>
318318
</dependency>
319319

320+
<!-- jMolecules -->
321+
322+
<dependency>
323+
<groupId>org.jmolecules</groupId>
324+
<artifactId>jmolecules-ddd</artifactId>
325+
<version>${jmolecules}</version>
326+
<scope>test</scope>
327+
</dependency>
328+
320329
</dependencies>
321330

322331
<build>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.bson.types.ObjectId;
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
25-
import org.springframework.data.annotation.Id;
2625
import org.springframework.data.mapping.Association;
2726
import org.springframework.data.mapping.MappingException;
2827
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
@@ -115,7 +114,7 @@ public boolean isIdProperty() {
115114
*/
116115
@Override
117116
public boolean isExplicitIdProperty() {
118-
return isAnnotationPresent(Id.class);
117+
return super.isIdProperty();
119118
}
120119

121120
/**

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/BasicMongoPersistentPropertyUnitTests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
import org.bson.Document;
3030
import org.bson.types.ObjectId;
31+
import org.jmolecules.ddd.annotation.Identity;
3132
import org.junit.jupiter.api.BeforeEach;
3233
import org.junit.jupiter.api.Test;
33-
3434
import org.springframework.core.annotation.AliasFor;
3535
import org.springframework.data.annotation.Id;
3636
import org.springframework.data.mapping.MappingException;
@@ -241,6 +241,15 @@ void fieldTypeShouldBeDocumentForPropertiesAnnotatedIdWhenAComplexTypeAndFieldTy
241241
assertThat(property.getFieldType()).isEqualTo(Document.class);
242242
}
243243

244+
@Test
245+
void considersJMoleculesIdentityExplicitlyAnnotatedIdentifier() {
246+
247+
MongoPersistentProperty property = getPropertyFor(WithJMoleculesIdentity.class, "identifier");
248+
249+
assertThat(property.isIdProperty()).isTrue();
250+
assertThat(property.isExplicitIdProperty()).isTrue();
251+
}
252+
244253
private MongoPersistentProperty getPropertyFor(Field field) {
245254
return getPropertyFor(entity, field);
246255
}
@@ -369,4 +378,8 @@ static class WithComplexId {
369378

370379
@Id @org.springframework.data.mongodb.core.mapping.Field ComplexId id;
371380
}
381+
382+
static class WithJMoleculesIdentity {
383+
@Identity ObjectId identifier;
384+
}
372385
}

0 commit comments

Comments
 (0)