diff --git a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java index b1b415fbd..c9e41dd0e 100644 --- a/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java +++ b/src/main/java/org/springframework/data/mapping/model/BasicPersistentEntity.java @@ -359,15 +359,14 @@ public class BasicPersistentEntity> implement * @see org.springframework.data.mapping.PersistentEntity#findAnnotation(java.lang.Class) */ @Override + @SuppressWarnings("unchecked") public A findAnnotation(Class annotationType) { - A annotation = annotationType.getAnnotation(annotationType); - - if (annotation != null) { - return annotation; + if (annotationCache.containsKey(annotationType)) { + return (A) annotationCache.get(annotationType); } - annotation = AnnotatedElementUtils.findMergedAnnotation(getType(), annotationType); + A annotation = AnnotatedElementUtils.findMergedAnnotation(getType(), annotationType); annotationCache.put(annotationType, annotation); return annotation; diff --git a/src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java b/src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java index f1d9d8db3..6e2031f7f 100644 --- a/src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/BasicPersistentEntityUnitTests.java @@ -274,9 +274,7 @@ public class BasicPersistentEntityUnitTests> { } @ComposedTypeAlias - static class AliasEntityUsingComposedAnnotation { - - } + static class AliasEntityUsingComposedAnnotation {} static class Subtype extends Entity {} }