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 9321297830..28ab4bf7aa 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 @@ -183,7 +183,29 @@ public abstract class AbstractQueryMethod implements MetaAttribute { } boolean isReactive() { - return MUTINY_SESSION.equals(sessionType); + return MUTINY_SESSION.equals(sessionType) + || UNI_MUTINY_SESSION.equals(sessionType); + } + + boolean isReactiveSession() { + return UNI_MUTINY_SESSION.equals(sessionType); + } + + String localSessionName() { + return isReactiveSession() ? "resolvedSession" : sessionName; + } + + void chainSession(StringBuilder declaration) { + // Reactive calls always have a return type + if ( isReactiveSession() ) { + declaration.append("\treturn ").append(sessionName).append(".chain(").append(localSessionName()).append(" -> {\n\t"); + } + } + + void chainSessionEnd(boolean isUpdate, StringBuilder declaration) { + if ( isReactiveSession() ) { + declaration.append("\n\t});"); + } } void setPage(StringBuilder declaration, String paramName, String paramType) { 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 20a48df577..26869f2888 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 @@ -459,7 +459,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { if ( method.getParameters().isEmpty() ) { final TypeMirror type = method.getReturnType(); if ( type.getKind() == TypeKind.DECLARED ) { - final DeclaredType declaredType = (DeclaredType) type; + final DeclaredType declaredType = ununi( (DeclaredType) type ); final Element element = declaredType.asElement(); if ( element.getKind() == ElementKind.INTERFACE ) { final Name name = ((TypeElement) element).getQualifiedName(); diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/CriteriaFinderMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/CriteriaFinderMethod.java index 6c7dcfce01..3a08a5f5ca 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/CriteriaFinderMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/CriteriaFinderMethod.java @@ -59,12 +59,14 @@ public class CriteriaFinderMethod extends AbstractFinderMethod { comment( declaration ); modifiers( declaration ); preamble( declaration, returnType(), paramTypes ); + chainSession( declaration ); nullChecks( paramTypes, declaration ); createCriteriaQuery( declaration ); where( declaration, paramTypes ); // orderBy( paramTypes, declaration ); executeQuery( declaration, paramTypes ); convertExceptions( declaration ); + chainSessionEnd( false, declaration ); closingBrace( declaration ); return declaration.toString(); } @@ -102,7 +104,7 @@ public class CriteriaFinderMethod extends AbstractFinderMethod { @Override void createQuery(StringBuilder declaration) { declaration - .append(sessionName) + .append(localSessionName()) .append(".createQuery(_query)\n"); } @@ -119,7 +121,7 @@ public class CriteriaFinderMethod extends AbstractFinderMethod { private void createCriteriaQuery(StringBuilder declaration) { declaration .append("\tvar _builder = ") - .append(sessionName) + .append(localSessionName()) .append(isUsingEntityManager() ? ".getEntityManagerFactory()" : ".getFactory()") diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/QueryMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/QueryMethod.java index dabbc8cbf9..9ccaa6b76b 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/QueryMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/jpamodelgen/annotation/QueryMethod.java @@ -85,6 +85,7 @@ public class QueryMethod extends AbstractQueryMethod { modifiers( paramTypes, declaration ); preamble( declaration, returnType, paramTypes ); collectOrdering( declaration, paramTypes ); + chainSession( declaration ); tryReturn( declaration, paramTypes, containerType ); castResult( declaration, returnType ); createQuery( declaration ); @@ -94,6 +95,7 @@ public class QueryMethod extends AbstractQueryMethod { unwrapped = applyOrder( declaration, paramTypes, containerType, unwrapped ); execute( declaration, unwrapped ); convertExceptions( declaration ); + chainSessionEnd( isUpdate, declaration ); closingBrace( declaration ); return declaration.toString(); } @@ -107,7 +109,7 @@ public class QueryMethod extends AbstractQueryMethod { @Override void createQuery(StringBuilder declaration) { declaration - .append(sessionName) + .append(localSessionName()) .append(isNative ? ".createNativeQuery" : ".createQuery") .append("(") .append(getConstantName()); 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 b8f050dcd2..c5759b90ca 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 @@ -98,6 +98,7 @@ public final class Constants { public static final String TUPLE = "jakarta.persistence.Tuple"; public static final String UNI = "io.smallrye.mutiny.Uni"; + public static final String UNI_MUTINY_SESSION = UNI+""; public static final String SINGULAR_ATTRIBUTE = "jakarta.persistence.metamodel.SingularAttribute"; public static final String COLLECTION_ATTRIBUTE = "jakarta.persistence.metamodel.CollectionAttribute"; @@ -129,7 +130,8 @@ public final class Constants { Constants.ENTITY_MANAGER, Constants.HIB_SESSION, Constants.HIB_STATELESS_SESSION, - Constants.MUTINY_SESSION + Constants.MUTINY_SESSION, + Constants.UNI_MUTINY_SESSION ); //TODO: this is not even an exhaustive list of built-in basic types