Skip to content

HHH-19565 @SQLRestriction should not be applied to a @ManyToOne #10381

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

gavinking
Copy link
Member

@gavinking gavinking commented Jun 20, 2025

Reverts to the behavior prior to H6.2, where @Where a.k.a. @SQLRestriction did not affect @OneToMany association fetching.

This change continues to add the restriction when:

  1. the @OneToMany is mapped to a @JoinTable, or
  2. when it's the unowned end of a @OneToOne mapped to a FK.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19565

@gavinking gavinking changed the title HHH-19565 test to reproduce bug HHH-19565 @SQLRestriction should not be applied to a @ManyToOne Jun 21, 2025
At least not when mapped to a foreign key association.

If we apply such a restriction, we will set the FK to null
when the entity is updated, resulting in data loss.

Note that this was the historical and correct behavior right
up until Hibernate 6.2. Some recent tests are asserting a
different and dangerous behavior, so I'm changing those tests.
…able

In this case, we won't set the FK to null. Instead, we can handle it with
an upsert (SQL MERGE).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant