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.
This commit is contained in:
Oliver Drotbohm
2021-09-07 14:54:12 +02:00
committed by Mark Paluch
parent 977e5e4c5c
commit ada7e199a4
3 changed files with 24 additions and 3 deletions

View File

@@ -317,6 +317,15 @@
<scope>test</scope>
</dependency>
<!-- jMolecules -->
<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-ddd</artifactId>
<version>${jmolecules}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@@ -22,7 +22,6 @@ import java.util.Set;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.model.AnnotationBasedPersistentProperty;
@@ -115,7 +114,7 @@ public class BasicMongoPersistentProperty extends AnnotationBasedPersistentPrope
*/
@Override
public boolean isExplicitIdProperty() {
return isAnnotationPresent(Id.class);
return super.isIdProperty();
}
/**

View File

@@ -28,9 +28,9 @@ import java.util.Locale;
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.springframework.core.annotation.AliasFor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mapping.MappingException;
@@ -241,6 +241,15 @@ public class BasicMongoPersistentPropertyUnitTests {
assertThat(property.getFieldType()).isEqualTo(Document.class);
}
@Test
void considersJMoleculesIdentityExplicitlyAnnotatedIdentifier() {
MongoPersistentProperty property = getPropertyFor(WithJMoleculesIdentity.class, "identifier");
assertThat(property.isIdProperty()).isTrue();
assertThat(property.isExplicitIdProperty()).isTrue();
}
private MongoPersistentProperty getPropertyFor(Field field) {
return getPropertyFor(entity, field);
}
@@ -369,4 +378,8 @@ public class BasicMongoPersistentPropertyUnitTests {
@Id @org.springframework.data.mongodb.core.mapping.Field ComplexId id;
}
static class WithJMoleculesIdentity {
@Identity ObjectId identifier;
}
}