diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractQueryMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractQueryMethod.java index 28ab4bf7aa..9aaac3c190 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractQueryMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AbstractQueryMethod.java @@ -204,7 +204,15 @@ public abstract class AbstractQueryMethod implements MetaAttribute { void chainSessionEnd(boolean isUpdate, StringBuilder declaration) { if ( isReactiveSession() ) { - declaration.append("\n\t});"); + declaration.append("\n\t})"); + // here we're checking for a boxed void and not Uni because the returnType has already + // been checked, and is ununi-ed + if ( isUpdate && returnTypeName != null && returnTypeName.equals(BOXED_VOID) ) { + declaration.append(".replaceWithVoid();"); + } + else { + declaration.append(";"); + } } } @@ -445,7 +453,7 @@ public abstract class AbstractQueryMethod implements MetaAttribute { .append(" _results = "); } else { - if ( !"void".equals(returnTypeName) ) { + if ( !"void".equals(returnTypeName) || isReactiveSession() ) { declaration .append("return "); } diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java index 51175a48aa..e0aa903cd2 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java @@ -1558,16 +1558,33 @@ public class AnnotationMetaEntity extends AnnotationMeta { @Nullable TypeMirror returnType, AnnotationMirror mirror, AnnotationValue value) { - if ( returnType == null - || returnType.getKind() != TypeKind.VOID - && returnType.getKind() != TypeKind.BOOLEAN - && returnType.getKind() != TypeKind.INT ) { + boolean reactive = usingReactiveSession( sessionType ); + if ( !isValidUpdateReturnType( returnType, method, reactive ) ) { context.message( method, mirror, value, - "return type of mutation query method must be 'int', 'boolean', or 'void'", + "return type of mutation query method must be " + (!reactive ? "'int', 'boolean' or 'void'" : "'Uni', 'Uni' or 'Uni'"), Diagnostic.Kind.ERROR ); } } + private boolean isValidUpdateReturnType(@Nullable TypeMirror returnType, ExecutableElement method, boolean reactive) { + if ( returnType == null ) { + return false; + } + if ( reactive ) { + // for reactive calls, don't use the returnType param, which has been ununi-ed, we want to check the full one + return method.getReturnType().toString().equals( Constants.UNI_VOID ) + || method.getReturnType().toString().equals( Constants.UNI_BOOLEAN ) + || method.getReturnType().toString().equals( Constants.UNI_INTEGER ); + + } + else { + // non-reactive + return returnType.getKind() == TypeKind.VOID + || returnType.getKind() == TypeKind.BOOLEAN + || returnType.getKind() == TypeKind.INT; + } + } + private void validateSelectHql( ExecutableElement method, @Nullable TypeMirror returnType, @@ -1955,7 +1972,8 @@ public class AnnotationMetaEntity extends AnnotationMeta { } private boolean usingReactiveSession(String sessionType) { - return Constants.MUTINY_SESSION.equals(sessionType); + return Constants.MUTINY_SESSION.equals(sessionType) + || Constants.UNI_MUTINY_SESSION.equals(sessionType); } private boolean usingStatelessSession(String sessionType) { diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/util/Constants.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/util/Constants.java index 747ee3eb4d..41eeb596ce 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/util/Constants.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/util/Constants.java @@ -99,6 +99,10 @@ public final class Constants { public static final String UNI = "io.smallrye.mutiny.Uni"; public static final String UNI_MUTINY_SESSION = UNI+""; + public static final String UNI_INTEGER = UNI+""; + public static final String UNI_VOID = UNI+""; + public static final String UNI_BOOLEAN = UNI+""; + public static final String BOXED_VOID = Void.class.getName(); public static final String SINGULAR_ATTRIBUTE = "jakarta.persistence.metamodel.SingularAttribute"; public static final String COLLECTION_ATTRIBUTE = "jakarta.persistence.metamodel.CollectionAttribute";