Skip to content

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).
Copy link
Member

@sebersole sebersole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add an entry to the migration guide

@gavinking
Copy link
Member Author

@sebersole Im not proposing to merge this as-is.

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.

2 participants