From 6b1b8d65eddd288b845f58d837b282200b6c484c Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 4 Apr 2024 11:31:34 +0200 Subject: [PATCH] look for primary entity type in indirectly-implemented interfaces for Jakarta Data TCK work Signed-off-by: Gavin King --- .../annotation/AnnotationMetaEntity.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java index f67851e6ae..32df57ab9e 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMetaEntity.java @@ -462,7 +462,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { } } - private @Nullable TypeElement primaryEntity(List lifecycleMethods) { + private static @Nullable TypeElement primaryEntity(TypeElement element) { for (TypeMirror typeMirror : element.getInterfaces()) { final DeclaredType declaredType = (DeclaredType) typeMirror; final TypeElement typeElement = (TypeElement) declaredType.asElement(); @@ -477,8 +477,27 @@ public class AnnotationMetaEntity extends AnnotationMeta { return (TypeElement) entityDeclared.asElement(); } } + else { + final TypeElement primaryEntity = primaryEntity(typeElement); + if ( primaryEntity != null ) { + return primaryEntity; + } + } } - TypeElement result = null; + return null; + } + + private @Nullable TypeElement primaryEntity(List lifecycleMethods) { + // first see if we are a subtype of DataRepository + // in that case, the first type argument determines + // the primary entity type + TypeElement result = primaryEntity(element); + if ( result != null ) { + return result; + } + // otherwise, we have to check all the lifecycle + // methods and determine if they all agree on the + // entity type; if so, it is the primary final Types types = context.getTypeUtils(); for ( ExecutableElement element : lifecycleMethods ) { if ( element.getParameters().size()==1 ) {