ruthst00 commented on code in PR #16573:
URL: https://github.com/apache/grails-core/pull/16573#discussion_r4409507879


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/QueryAliasRegistrar.java:
##########
@@ -0,0 +1,157 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.orm.hibernate.query;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import jakarta.persistence.criteria.JoinType;
+import jakarta.persistence.criteria.Root;
+
+import grails.gorm.DetachedCriteria;
+import org.grails.datastore.gorm.query.criteria.DetachedAssociationCriteria;
+import org.grails.datastore.mapping.model.types.Association;
+import org.grails.datastore.mapping.model.types.Basic;
+import org.grails.datastore.mapping.query.Query;
+
+/**
+ * Works out which aliases a criteria query declares and registers them, with 
their join types, in the
+ * {@link JpaQueryContext} the query is built against.
+ *
+ * <p>An alias comes from three places: one created explicitly with {@code 
createAlias}, an association
+ * criterion that names an alias, and a dotted property name whose first 
segment is an implicit alias. A join
+ * type configured on the {@link DetachedCriteria} is applied to the alias of 
the same path.</p>
+ *
+ * @since 8.0.1
+ */
+final class QueryAliasRegistrar {
+
+    private final DetachedCriteria<?> detachedCriteria;
+    private final HibernateQuery hibernateQuery;
+
+    /**
+     * @param detachedCriteria the criteria whose aliases and join types are 
registered
+     * @param hibernateQuery the query that holds aliases created through 
{@code createAlias}, or {@code null}
+     */
+    QueryAliasRegistrar(DetachedCriteria<?> detachedCriteria, HibernateQuery 
hibernateQuery) {
+        this.detachedCriteria = detachedCriteria;
+        this.hibernateQuery = hibernateQuery;
+    }
+
+    /**
+     * Creates the context a query or subquery is built against, registers 
every alias the criteria declare,
+     * and materializes explicitly requested entity association joins even 
when no expression references their aliases.
+     *
+     * @param parent the context of the enclosing query, or {@code null} for a 
top level query
+     * @param root the root of the query
+     * @return the context, with its aliases registered and explicit entity 
association joins materialized
+     */
+    JpaQueryContext createContext(JpaQueryContext parent, Root<?> root) {
+        List<HibernateAlias> aliases = explicitAliases();
+        JpaQueryContext context = JpaQueryContext.forSubquery(parent, aliases, 
root);
+        registerDetachedJoins(context);
+        discover(detachedCriteria.getCriteria(), context);
+        for (HibernateAlias alias : aliases) {
+            if 
(!(detachedCriteria.getPersistentEntity().getPropertyByName(alias.path()) 
instanceof Basic)) {

Review Comment:
   Fixed in 
https://github.com/apache/grails-core/pull/16573/changes/a151e11ec7fe529da7ae6cf3e32ee05306a48753



-- 
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