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 7f0d6ac923..1cde8a8058 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 @@ -304,16 +304,17 @@ public class AnnotationMetaEntity extends AnnotationMeta { final DeclaredType declaredType = (DeclaredType) returnType; final List typeArguments = declaredType.getTypeArguments(); if ( typeArguments.size() == 0 ) { + final String typeName = declaredType.toString(); if ( containsAnnotation( declaredType.asElement(), Constants.ENTITY ) ) { - addQueryMethod(method, methodName, declaredType.toString(), null); + addQueryMethod(method, methodName, typeName, null); } else { - final String containerTypeName = declaredType.toString(); - if (isLegalRawResultType(containerTypeName)) { - addQueryMethod(method, methodName, null, containerTypeName); + if (isLegalRawResultType(typeName)) { + addQueryMethod(method, methodName, null, typeName); } else { - displayError(method, "incorrect return type '" + containerTypeName + "'"); + // probably a projection + addQueryMethod(method, methodName, typeName, null); } } } @@ -342,7 +343,8 @@ public class AnnotationMetaEntity extends AnnotationMeta { private static boolean isLegalGenericResultType(String containerTypeName) { return containerTypeName.equals("java.util.List") || containerTypeName.equals("jakarta.persistence.TypedQuery") - || containerTypeName.equals("org.hibernate.query.Query"); + || containerTypeName.equals("org.hibernate.query.Query") + || containerTypeName.equals("org.hibernate.query.SelectionQuery"); } private void addQueryMethod( 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 91d01c956c..3703919391 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 @@ -86,7 +86,8 @@ public class QueryMethod implements MetaAttribute { .append(")") .append(" {") .append("\n return "); - if ( isNative && returnTypeName != null ) { + if ( isNative && returnTypeName != null + || containerTypeName != null && containerTypeName.startsWith("org.hibernate") ) { declaration.append("(").append(type).append(") "); } declaration