Browse Source

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.
pull/28/head
Oliver Gierke 13 years ago
parent
commit
0cf875b358
  1. 2
      src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java
  2. 13
      src/test/java/org/springframework/data/mapping/model/AbstractAnnotationBasedPropertyUnitTests.java

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

@ -82,7 +82,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp @@ -82,7 +82,7 @@ public abstract class AnnotationBasedPersistentProperty<P extends PersistentProp
Class<? extends Annotation> annotationType = annotation.annotationType();
if (annotationCache.containsKey(annotationType)) {
if (annotationCache.containsKey(annotationType) && !annotationCache.get(annotationType).equals(annotation)) {
throw new MappingException(String.format("Ambiguous mapping! Annotation %s configured "
+ "multiple times on accessor methods of property %s in class %s!", annotationType, getName(), getOwner()
.getType().getName()));

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

@ -136,6 +136,7 @@ public class AbstractAnnotationBasedPropertyUnitTests<P extends AnnotationBasedP @@ -136,6 +136,7 @@ public class AbstractAnnotationBasedPropertyUnitTests<P extends AnnotationBasedP
String field;
String getter;
String setter;
String doubleMapping;
@MyAnnotationAsMeta
String meta;
@ -157,6 +158,16 @@ public class AbstractAnnotationBasedPropertyUnitTests<P extends AnnotationBasedP @@ -157,6 +158,16 @@ public class AbstractAnnotationBasedPropertyUnitTests<P extends AnnotationBasedP
public String getOverride() {
return override;
}
@MyAnnotation
public String getDoubleMapping() {
return doubleMapping;
}
@MyAnnotation
public void setDoubleMapping(String doubleMapping) {
this.doubleMapping = doubleMapping;
}
}
static class InvalidSample {
@ -168,7 +179,7 @@ public class AbstractAnnotationBasedPropertyUnitTests<P extends AnnotationBasedP @@ -168,7 +179,7 @@ public class AbstractAnnotationBasedPropertyUnitTests<P extends AnnotationBasedP
return meta;
}
@MyAnnotation
@MyAnnotation("foo")
public void setMeta(String meta) {
this.meta = meta;
}

Loading…
Cancel
Save