Skip to content

Commit 0cf875b

Browse files
committed
DATACMNS-320 - Be less restrictive in finding mapping ambiguities.
So far we threw exceptions in case we find the same exception on getters *and* setters. We now allow this scenario in case the annotations are semantically equivalent.
1 parent 454defc commit 0cf875b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private final void populateAnnotationCache(Field field) {
8282

8383
Class<? extends Annotation> annotationType = annotation.annotationType();
8484

85-
if (annotationCache.containsKey(annotationType)) {
85+
if (annotationCache.containsKey(annotationType) && !annotationCache.get(annotationType).equals(annotation)) {
8686
throw new MappingException(String.format("Ambiguous mapping! Annotation %s configured "
8787
+ "multiple times on accessor methods of property %s in class %s!", annotationType, getName(), getOwner()
8888
.getType().getName()));

src/test/java/org/springframework/data/mapping/model/AbstractAnnotationBasedPropertyUnitTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ static class Sample {
136136
String field;
137137
String getter;
138138
String setter;
139+
String doubleMapping;
139140

140141
@MyAnnotationAsMeta
141142
String meta;
@@ -157,6 +158,16 @@ public void setSetter(String setter) {
157158
public String getOverride() {
158159
return override;
159160
}
161+
162+
@MyAnnotation
163+
public String getDoubleMapping() {
164+
return doubleMapping;
165+
}
166+
167+
@MyAnnotation
168+
public void setDoubleMapping(String doubleMapping) {
169+
this.doubleMapping = doubleMapping;
170+
}
160171
}
161172

162173
static class InvalidSample {
@@ -168,7 +179,7 @@ public String getMeta() {
168179
return meta;
169180
}
170181

171-
@MyAnnotation
182+
@MyAnnotation("foo")
172183
public void setMeta(String meta) {
173184
this.meta = meta;
174185
}

0 commit comments

Comments
 (0)