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 6f1a991d2..c260ac250 100644 --- a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java @@ -15,11 +15,15 @@ */ package org.springframework.data.mapping.model; +import static org.springframework.core.annotation.AnnotationUtils.*; + import java.beans.PropertyDescriptor; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -42,6 +46,7 @@ public abstract class AnnotationBasedPersistentProperty

{ private final Value value; + private final Map, Annotation> annotationCache = new HashMap, Annotation>(); /** * Creates a new {@link AnnotationBasedPersistentProperty}. @@ -112,10 +117,15 @@ public abstract class AnnotationBasedPersistentProperty

A findAnnotation(Class annotationType) { + @SuppressWarnings("unchecked") + public A findAnnotation(Class annotationType) { Assert.notNull(annotationType, "Annotation type must not be null!"); + if (annotationCache != null && annotationCache.containsKey(annotationType)) { + return (A) annotationCache.get(annotationType); + } + for (Method method : Arrays.asList(getGetter(), getSetter())) { if (method == null) { @@ -125,11 +135,26 @@ public abstract class AnnotationBasedPersistentProperty

A cacheAndReturn(Class type, A annotation) { + + if (annotationCache != null) { + annotationCache.put(type, annotation); + } + + return annotation; } /**