File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -2120,6 +2120,7 @@ private void addQueryMethod(
21202120 method .getSimpleName ().toString (),
21212121 processedQuery ,
21222122 returnType == null ? null : returnType .toString (),
2123+ returnType == null ? null : returnTypeClass ( returnType ),
21232124 containerTypeName ,
21242125 paramNames ,
21252126 paramTypes ,
@@ -2137,6 +2138,36 @@ private void addQueryMethod(
21372138 }
21382139 }
21392140
2141+ private static String returnTypeClass (TypeMirror returnType ) {
2142+ switch (returnType .getKind ()) {
2143+ case DECLARED :
2144+ DeclaredType declaredType = (DeclaredType ) returnType ;
2145+ final TypeElement typeElement = (TypeElement ) declaredType .asElement ();
2146+ return typeElement .getQualifiedName ().toString ();
2147+ case INT :
2148+ return "int" ;
2149+ case LONG :
2150+ return "long" ;
2151+ case SHORT :
2152+ return "short" ;
2153+ case BYTE :
2154+ return "byte" ;
2155+ case BOOLEAN :
2156+ return "boolean" ;
2157+ case FLOAT :
2158+ return "float" ;
2159+ case DOUBLE :
2160+ return "double" ;
2161+ case CHAR :
2162+ return "char" ;
2163+ case ARRAY :
2164+ final ArrayType arrayType = (ArrayType ) returnType ;
2165+ return returnTypeClass ( arrayType .getComponentType () ) + "[]" ;
2166+ default :
2167+ return returnType .toString ();
2168+ }
2169+ }
2170+
21402171 private @ Nullable String implicitEntityName (@ Nullable DeclaredType resultType ) {
21412172 if ( resultType != null && hasAnnotation (resultType .asElement (), ENTITY ) ) {
21422173 final AnnotationMirror annotation =
Original file line number Diff line number Diff line change 2323 */
2424public class QueryMethod extends AbstractQueryMethod {
2525 private final String queryString ;
26+ private final @ Nullable String returnTypeClass ;
2627 private final @ Nullable String containerType ;
2728 private final boolean isUpdate ;
2829 private final boolean isNative ;
@@ -35,6 +36,8 @@ public class QueryMethod extends AbstractQueryMethod {
3536 @ Nullable
3637 String returnTypeName ,
3738 @ Nullable
39+ String returnTypeClass ,
40+ @ Nullable
3841 String containerType ,
3942 List <String > paramNames ,
4043 List <String > paramTypes ,
@@ -54,6 +57,7 @@ public class QueryMethod extends AbstractQueryMethod {
5457 addNonnullAnnotation ,
5558 dataRepository );
5659 this .queryString = queryString ;
60+ this .returnTypeClass = returnTypeClass ;
5761 this .containerType = containerType ;
5862 this .isUpdate = isUpdate ;
5963 this .isNative = isNative ;
@@ -117,10 +121,10 @@ void createQuery(StringBuilder declaration) {
117121 .append (createQueryMethod ())
118122 .append ("(" )
119123 .append (getConstantName ());
120- if ( returnTypeName != null && !isUpdate ) {
124+ if ( returnTypeClass != null && !isUpdate ) {
121125 declaration
122126 .append (", " )
123- .append (annotationMetaEntity .importType (returnTypeName ))
127+ .append (annotationMetaEntity .importType (returnTypeClass ))
124128 .append (".class" );
125129 }
126130 declaration .append (")\n " );
You can’t perform that action at this time.
0 commit comments