jamesfredley commented on code in PR #16559:
URL: https://github.com/apache/grails-core/pull/16559#discussion_r4407447152


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/ExpressionResolver.java:
##########
@@ -48,7 +48,12 @@ public Expression<?> resolve(String path) {
             cleanPath = cleanPath.substring(5);
         }
 
-        // 1. Check for materialized aliases (Materialized Selects/Joins)
+        // 1. Check for materialized aliases (Materialized Selects/Joins), a 
join from THIS root first, for the reason
+        //    given in resolveFromAlias
+        From<?, ?> local = joinTracker.getLocalJoin(cleanPath);
+        if (local != null) {

Review Comment:
   Pet.createCriteria().list { owner { isNotNull('id') }; projections { 
min('owner.age', 'owner') }; order('owner') } materializes the owner join and 
then registers MIN(owner.age) under the same name. This return uses the join, 
so ORDER BY is the owner row rather than the aggregate and a strict-grouping 
database rejects the query. Prefer a join from this root over an alias 
inherited from an outer query, and keep a projection alias realized in this 
query ahead of that join.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to