I implemented the approach that I proposed in the issue and a test in
It detects left joins with join tables that use the target table alias.
The join table is replaced with a subquery and the WITH clause is moved
to the join of the subquery.
hibernate-dev mailing list