ruthst00 commented on code in PR #16573:
URL: https://github.com/apache/grails-core/pull/16573#discussion_r4351278664
##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/ExpressionResolver.java:
##########
@@ -112,7 +120,27 @@ 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());
+ Path<?> path = getPath(joinTracker.getRoot(), def.path());
+ boolean elementCollection = path != null && path.getModel()
instanceof PluralAttribute<?, ?, ?> attribute &&
+ attribute.getPersistentAttributeType() ==
PersistentAttributeType.ELEMENT_COLLECTION;
+ // Entity association criteria and their alias share a join.
Element collection aliases
+ // are independent joins and must not replace the
collection-valued path itself.
+ aliased = elementCollection ? null :
joinTracker.getOwnJoin(def.path());
+ boolean explicitAlias = !alias.equals(def.path());
+ // Reuse an association join only for its first explicit
alias. A second alias
+ // must be able to restrict a different element of an
entity-valued collection.
+ if (explicitAlias && explicitlyAliasedJoins.contains(aliased))
{
+ aliased = null;
+ }
+ if (aliased == null) {
+ aliased = joinTracker.getRoot().join(def.path(),
def.joinType());
+ if (!elementCollection &&
joinTracker.getOwnJoin(def.path()) == null) {
Review Comment:
Fixed in
https://github.com/apache/grails-core/pull/16573/changes/644adf856e2c22496ccc06136af67aa30de5f7b1
--
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]