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 1238e453a7..194b7d22ea 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 @@ -2120,6 +2120,7 @@ public class AnnotationMetaEntity extends AnnotationMeta { method.getSimpleName().toString(), processedQuery, returnType == null ? null : returnType.toString(), + returnType == null ? null : returnTypeClass( returnType ), containerTypeName, paramNames, paramTypes, @@ -2137,6 +2138,36 @@ public class AnnotationMetaEntity extends AnnotationMeta { } } + private static String returnTypeClass(TypeMirror returnType) { + switch (returnType.getKind()) { + case DECLARED: + DeclaredType declaredType = (DeclaredType) returnType; + final TypeElement typeElement = (TypeElement) declaredType.asElement(); + return typeElement.getQualifiedName().toString(); + case INT: + return "int"; + case LONG: + return "long"; + case SHORT: + return "short"; + case BYTE: + return "byte"; + case BOOLEAN: + return "boolean"; + case FLOAT: + return "float"; + case DOUBLE: + return "double"; + case CHAR: + return "char"; + case ARRAY: + final ArrayType arrayType = (ArrayType) returnType; + return returnTypeClass( arrayType.getComponentType() ) + "[]"; + default: + return returnType.toString(); + } + } + private @Nullable String implicitEntityName(@Nullable DeclaredType resultType) { if ( resultType != null && hasAnnotation(resultType.asElement(), ENTITY) ) { final AnnotationMirror annotation = diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/QueryMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/QueryMethod.java index 5f69ca286f..d05417b5a2 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/QueryMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/QueryMethod.java @@ -23,6 +23,7 @@ import static org.hibernate.processor.util.StringUtil.getUpperUnderscoreCaseFrom */ public class QueryMethod extends AbstractQueryMethod { private final String queryString; + private final @Nullable String returnTypeClass; private final @Nullable String containerType; private final boolean isUpdate; private final boolean isNative; @@ -35,6 +36,8 @@ public class QueryMethod extends AbstractQueryMethod { @Nullable String returnTypeName, @Nullable + String returnTypeClass, + @Nullable String containerType, List paramNames, List paramTypes, @@ -54,6 +57,7 @@ public class QueryMethod extends AbstractQueryMethod { addNonnullAnnotation, dataRepository ); this.queryString = queryString; + this.returnTypeClass = returnTypeClass; this.containerType = containerType; this.isUpdate = isUpdate; this.isNative = isNative; @@ -117,10 +121,10 @@ public class QueryMethod extends AbstractQueryMethod { .append(createQueryMethod()) .append("(") .append(getConstantName()); - if ( returnTypeName != null && !isUpdate ) { + if ( returnTypeClass != null && !isUpdate ) { declaration .append(", ") - .append(annotationMetaEntity.importType(returnTypeName)) + .append(annotationMetaEntity.importType(returnTypeClass)) .append(".class"); } declaration.append(")\n");