diff --git a/src/main/java/io/ebean/util/AnnotationUtil.java b/src/main/java/io/ebean/util/AnnotationUtil.java index 1aa7e421c..de82dc460 100644 --- a/src/main/java/io/ebean/util/AnnotationUtil.java +++ b/src/main/java/io/ebean/util/AnnotationUtil.java @@ -104,7 +104,7 @@ public class AnnotationUtil { } /** - * Finds all annotations recusively for a class and its superclasses. + * Finds all annotations recusively for a class and its superclasses or interfaces. */ public static Set findAnnotationsRecursive(Class clazz, Class annotationType) { if (annotationType == null) { @@ -112,13 +112,28 @@ public class AnnotationUtil { } Set ret = new LinkedHashSet<>(); Set visited = new HashSet<>(); - while (clazz != null && clazz != Object.class) { - findMetaAnnotations(clazz, annotationType, ret, visited); + Set> visitedInterfaces = new HashSet<>(); + while (clazz != null && !clazz.getName().startsWith("java.lang.")) { + findMetaAnnotationsRecursive(clazz, annotationType, ret, visited, visitedInterfaces); clazz = clazz.getSuperclass(); } return ret; } + /** + * Searches the interfaces for annotations. + */ + private static void findMetaAnnotationsRecursive(Class clazz, + Class annotationType, Set ret, + Set visited, Set> visitedInterfaces) { + findMetaAnnotations(clazz, annotationType, ret, visited); + for (Class iface : clazz.getInterfaces()) { + if (!iface.getName().startsWith("java.lang.") && visitedInterfaces.add(iface)) { + findMetaAnnotationsRecursive(iface, annotationType, ret, visited, visitedInterfaces); + } + } + } + /** * Perform the search algorithm avoiding endless recursion by tracking which * annotations have already been visited.