fix error message when repository backed by regular session returns Uni

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-14 23:32:18 +02:00
parent 6695617210
commit adec141a7f
1 changed files with 13 additions and 5 deletions

View File

@ -1116,7 +1116,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
addQueryMethod( method, returnType, null ); addQueryMethod( method, returnType, null );
} }
else if ( kind == TypeKind.DECLARED ) { else if ( kind == TypeKind.DECLARED ) {
final DeclaredType declaredType = (DeclaredType) ununi( returnType ); final DeclaredType declaredType = (DeclaredType) ununiIfPossible(method, returnType);
final TypeElement typeElement = (TypeElement) declaredType.asElement(); final TypeElement typeElement = (TypeElement) declaredType.asElement();
final List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); final List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
switch ( typeArguments.size() ) { switch ( typeArguments.size() ) {
@ -1148,6 +1148,14 @@ 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);
}
return result;
}
private boolean validatedQueryReturnType(ExecutableElement method, TypeElement typeElement) { private boolean validatedQueryReturnType(ExecutableElement method, TypeElement typeElement) {
final String typeName = typeElement.getQualifiedName().toString(); final String typeName = typeElement.getQualifiedName().toString();
switch ( typeName ) { switch ( typeName ) {
@ -1284,13 +1292,13 @@ public class AnnotationMetaEntity extends AnnotationMeta {
Diagnostic.Kind.ERROR); Diagnostic.Kind.ERROR);
} }
else { else {
createCriteriaDelete(method, returnType); createCriteriaDelete(method);
} }
} }
} }
private void addLifecycleMethod(ExecutableElement method) { private void addLifecycleMethod(ExecutableElement method) {
final TypeMirror returnType = ununi(method.getReturnType()); final TypeMirror returnType = ununiIfPossible( method, method.getReturnType() );
if ( method.getParameters().size() != 1 ) { if ( method.getParameters().size() != 1 ) {
message( method, message( method,
"must have exactly one parameter", "must have exactly one parameter",
@ -1474,7 +1482,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
} }
} }
else if ( returnType.getKind() == TypeKind.DECLARED ) { else if ( returnType.getKind() == TypeKind.DECLARED ) {
final DeclaredType declaredType = (DeclaredType) ununi( returnType ); final DeclaredType declaredType = (DeclaredType) ununiIfPossible(method, returnType);
final TypeElement entity = (TypeElement) declaredType.asElement(); final TypeElement entity = (TypeElement) declaredType.asElement();
if ( !containsAnnotation( entity, ENTITY ) ) { if ( !containsAnnotation( entity, ENTITY ) ) {
message( method, message( method,
@ -1581,7 +1589,7 @@ public class AnnotationMetaEntity extends AnnotationMeta {
} }
} }
private void createCriteriaDelete(ExecutableElement method, TypeMirror returnType) { private void createCriteriaDelete(ExecutableElement method) {
final TypeElement entity = primaryEntity; final TypeElement entity = primaryEntity;
if ( entity == null) { if ( entity == null) {
message( method, "repository does not have a well-defined primary entity type", message( method, "repository does not have a well-defined primary entity type",