Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-17837 Join + GroupBy: Wrong column used for many-to-many association #8274

Merged
merged 2 commits into from May 3, 2024

Conversation

mbladel
Copy link
Member

@mbladel mbladel commented Apr 30, 2024

@mbladel
Copy link
Member Author

mbladel commented Apr 30, 2024

This PR effectively aligns the behavior of explicit joins with plural paths (i.e. to-many associations) with what was previously done for to-ones: explicitly requesting a join will now always produce an actual join in the generated query, effectively disabling any foreign-key optimizations. This allows us to ensure the correct "side" of the FK is used wrt group by / order by clauses.

Because of the change in behavior, I had to adapt a couple existing tests that were asserting the number of joins in generated queries. See also the Jira comments for more details.

@mbladel
Copy link
Member Author

mbladel commented Apr 30, 2024

After initial discussion with @beikov, we opted to preserve foreign-key optimizations whenever possible: we will only force using the association target type's table when the key property being selected is also found in the group by clause of the query. In all other cases, explicit joins will preserve table-group laziness, only initializing it when needed.

Also, change how we determine whether we need to use the target-side to only the strictly needed cases (non-optimizable joins, `group by` or `order by` clauses)
@mbladel mbladel merged commit b16b891 into hibernate:main May 3, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants