ruthst00 commented on code in PR #16573:
URL: https://github.com/apache/grails-core/pull/16573#discussion_r4340120733
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/ExpressionResolver.java:
##########
@@ -112,7 +112,13 @@ private Expression<?> resolveFromAlias(String alias,
String subPath) {
if (aliasRegistry.isDefined(alias)) {
HibernateAlias def = aliasRegistry.getDefinition(alias);
if (def != null && def.path() != null) {
- aliased = joinTracker.getRoot().join(def.path(),
def.joinType());
+ // The association criteria and its alias must refer to the
same physical join,
+ // regardless of whether a predicate, projection or order
resolves it first.
+ aliased = joinTracker.getJoin(def.path());
Review Comment:
Fixed in
https://github.com/apache/grails-core/pull/16573/changes/69b2726dae41b3d6f514c9c59f4ad349d8532907
##########
grails-data-hibernate7/core/src/test/groovy/grails/gorm/tests/CreateAliasJoinSpec.groovy:
##########
@@ -0,0 +1,206 @@
+/*
+ * 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 grails.gorm.tests
+
+import jakarta.persistence.criteria.JoinType
+import org.hibernate.resource.jdbc.spi.StatementInspector
+import spock.lang.Issue
+import spock.lang.Shared
+
+import grails.gorm.DetachedCriteria
+import grails.gorm.annotation.Entity
+
+@Issue('https://github.com/apache/grails-core/issues/16562')
+class CreateAliasJoinSpec extends HibernateGormDatastoreSpec {
+
+ @Shared
+ CreateAliasSqlCapture sqlCapture = new CreateAliasSqlCapture()
+
+ void setupSpec() {
+ manager.grailsConfig.hibernate.session_factory.statement_inspector =
sqlCapture
+ manager.registerDomainClasses(CreateAliasTeam, CreateAliasLike)
+ }
+
+ void setup() {
+ sqlCapture.statements.clear()
+ }
+
+ void 'a to-many alias does not multiply projected rows or counts'() {
Review Comment:
Fixed in
https://github.com/apache/grails-core/pull/16573/changes/69b2726dae41b3d6f514c9c59f4ad349d8532907
--
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]