You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hibernate 7: a subquery projecting a path through an association correlates with a top-level association block of createCriteria #16762
should select the pets of Homer whose name is the first name of the owner of any pet.
Actual Behaviour
The subquery takes owner from the outer query and comes out correlated:
... from pet p1_0 join person o1_0 ono1_0.id=p1_0.owner_idwhereo1_0.first_name=?
andp1_0.namein ((selecto3_0.first_namefrom pet p2_0, person o3_0 whereo3_0.id=p1_0.owner_id))
so it only matches pets named after their own owner, and the result depends on whether the owner { ... } block comes before or after the subquery.
The same query built with new DetachedCriteria(Pet).build { ... }, and a subquery inside a nested block, are not affected (covered by #16559).
Cause
In the createCriteria builder every association block records a join type (CriteriaMethodInvoker calls hibernateQuery.join(name, joinType), INNER when none is given), and JpaCriteriaQueryCreator.registerDetachedJoins turns each recorded join type into an alias definition named after the path. A subquery context looks these up through its parent: ExpressionResolver sees owner as a defined alias (AliasRegistry.isDefined / getDefinition walk the parent registries) and then takes the outer join from the parent JoinTracker.
A join type recorded for an association block is not an alias the user named, so it should not be visible to a subquery; only explicit aliases (createAlias, as) should correlate.
Steps To Reproduce
Run the query above on Hibernate 7 with a Pet that has an owner (Person) and a pet named after the first name of another pet's owner.
Activity
Preserve alias declaration scope and prevent implicit alias leakage i…
Resolve base association when materializing nested aliases to preserv…