diff --git a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java index 6c6294bd7..ebd96b353 100644 --- a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java @@ -107,13 +107,15 @@ public abstract class AnnotationBasedPersistentProperty

annotationType = annotation.annotationType(); - validateAnnotation(annotation, + Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType); + + validateAnnotation(mergedAnnotation, "Ambiguous mapping! Annotation %s configured " + "multiple times on accessor methods of property %s in class %s!", annotationType.getSimpleName(), getName(), getOwner().getType().getSimpleName()); annotationCache.put(annotationType, - Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(it, annotationType))); + Optional.of(mergedAnnotation)); } }); @@ -122,13 +124,14 @@ public abstract class AnnotationBasedPersistentProperty

annotationType = annotation.annotationType(); + Annotation mergedAnnotation = AnnotatedElementUtils.getMergedAnnotation(it, annotationType); - validateAnnotation(annotation, + validateAnnotation(mergedAnnotation, "Ambiguous mapping! Annotation %s configured " + "on field %s and one of its accessor methods in class %s!", annotationType.getSimpleName(), it.getName(), getOwner().getType().getSimpleName()); annotationCache.put(annotationType, - Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(it, annotationType))); + Optional.of(mergedAnnotation)); } }); } diff --git a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java index f5daba521..5abaedb50 100755 --- a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java @@ -331,6 +331,7 @@ public class AnnotationBasedPersistentPropertyUnitTests