@@ -1541,23 +1541,26 @@ private void missingTypeArgError(String entity, VariableElement parameter, boole
15411541 Diagnostic .Kind .ERROR );
15421542 }
15431543
1544- private List <OrderBy > orderByList (ExecutableElement method , TypeElement entityType ) {
1545- final AnnotationMirror orderByList =
1546- getAnnotationMirror ( method , "jakarta.data.repository.OrderBy.List" );
1547- if ( orderByList != null ) {
1548- final List <OrderBy > result = new ArrayList <>();
1549- @ SuppressWarnings ("unchecked" )
1550- final List <AnnotationValue > list = (List <AnnotationValue >)
1551- castNonNull ( getAnnotationValue ( orderByList , "value" ) ).getValue ();
1552- for ( AnnotationValue element : list ) {
1553- result .add ( orderByExpression ( castNonNull ( (AnnotationMirror ) element .getValue () ), entityType , method ) );
1554- }
1555- return result ;
1556- }
1557- final AnnotationMirror orderBy =
1558- getAnnotationMirror ( method , "jakarta.data.repository.OrderBy" );
1559- if ( orderBy != null ) {
1560- return List .of ( orderByExpression (orderBy , entityType , method ) );
1544+ private List <OrderBy > orderByList (ExecutableElement method , TypeElement returnType ) {
1545+ final TypeElement entityType = implicitEntityType ( returnType );
1546+ if ( entityType != null ) {
1547+ final AnnotationMirror orderByList =
1548+ getAnnotationMirror ( method , "jakarta.data.repository.OrderBy.List" );
1549+ if ( orderByList != null ) {
1550+ final List <OrderBy > result = new ArrayList <>();
1551+ @ SuppressWarnings ("unchecked" )
1552+ final List <AnnotationValue > list = (List <AnnotationValue >)
1553+ castNonNull ( getAnnotationValue ( orderByList , "value" ) ).getValue ();
1554+ for ( AnnotationValue element : list ) {
1555+ result .add ( orderByExpression ( castNonNull ( (AnnotationMirror ) element .getValue () ), entityType , method ) );
1556+ }
1557+ return result ;
1558+ }
1559+ final AnnotationMirror orderBy =
1560+ getAnnotationMirror ( method , "jakarta.data.repository.OrderBy" );
1561+ if ( orderBy != null ) {
1562+ return List .of ( orderByExpression (orderBy , entityType , method ) );
1563+ }
15611564 }
15621565 return emptyList ();
15631566 }
@@ -2214,6 +2217,18 @@ else if ( primaryEntity != null ) {
22142217 }
22152218 }
22162219
2220+ private @ Nullable TypeElement implicitEntityType (@ Nullable TypeElement resultType ) {
2221+ if ( resultType != null && hasAnnotation (resultType , ENTITY ) ) {
2222+ return resultType ;
2223+ }
2224+ else if ( primaryEntity != null ) {
2225+ return primaryEntity ;
2226+ }
2227+ else {
2228+ return null ;
2229+ }
2230+ }
2231+
22172232 private static String entityName (DeclaredType resultType , AnnotationMirror annotation ) {
22182233 final AnnotationValue name = getAnnotationValue (annotation , "name" );
22192234 if (name != null ) {
0 commit comments