From 5ab2d83bd82e9d7db2f84cee8efed10925956a94 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Fri, 26 Apr 2024 23:28:43 +0200 Subject: [PATCH] produce meaningful error if reactive repo method does not return Uni Signed-off-by: Gavin King --- .../annotation/AnnotationMetaEntity.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 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 2c17dcae41..0978e957a0 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 @@ -1149,9 +1149,18 @@ public class AnnotationMetaEntity extends AnnotationMeta { } private TypeMirror ununiIfPossible(ExecutableElement method, TypeMirror returnType) { - final TypeMirror result = ununi(returnType); - if ( result != returnType && repository && !usingReactiveSession(sessionType) ) { - message(method, "not backed by a reactive session", Diagnostic.Kind.ERROR); + final TypeMirror result = ununi( returnType ); + if ( repository ) { + if ( usingReactiveSession( sessionType ) ) { + if ( result == returnType ) { + message( method, "backed by a reactive session, must return 'Uni'", Diagnostic.Kind.ERROR ); + } + } + else { + if ( result != returnType ) { + message( method, "not backed by a reactive session, must not return 'Uni'", Diagnostic.Kind.ERROR ); + } + } } return result; } @@ -1482,7 +1491,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { } } else if ( returnType.getKind() == TypeKind.DECLARED ) { - final DeclaredType declaredType = (DeclaredType) ununiIfPossible(method, returnType); + final DeclaredType declaredType = (DeclaredType) returnType; final TypeElement entity = (TypeElement) declaredType.asElement(); if ( !containsAnnotation( entity, ENTITY ) ) { message( method,