jdaugherty opened a new pull request, #16742: URL: https://github.com/apache/grails-core/pull/16742
## Description Fixes #16740. With GORM for Hibernate 5 in 8.0.0, `save()` on the owning side of a bidirectional one-to-one no longer set the back-reference of a new child whose back-reference was still null. Depending on the mapping the child was stored with a null in-memory back-reference, its insert failed with `NULL not allowed for column AUTHOR_ID` when the foreign key is in the child (`hasOne`), or cascaded validation rejected a non-nullable back-reference. 7.2.x sets it. `HibernateRuntimeUtils.autoAssociateBidirectionalOneToOnes()` skipped the association unless `proxyHandler.isInitialized(child, backReference)` was true. The Hibernate 7 work made `HibernateProxyHandler.isInitialized(null)` return `false` (it returned `true` on 7.x through `Hibernate.isInitialized(null)`), so that check now skipped exactly the null back-reference the method exists to fill. A non-null back-reference is never overwritten, initialized or not, so the check only ever changed the outcome for `null`. This PR drops it; the earlier check on the owner's property still keeps an uninitialized child proxy from being loaded, and the Hibernate 7 module's copy of the method already has no such check. `OneToOneBackReferenceSpec` saves the owner without setting the back-reference for a foreign key in the owner, a `hasOne`, and a `hasOne` without `belongsTo` with a non-nullable back-reference, each for a new and a persisted owner, plus a subclass child, a pre-set back-reference that must be left alone, and an uninitialized child proxy that must stay uninitialized. Six of its eight features fail without the fix with the three failure modes from the issue. Verified locally: the new spec (red before, green after), `:grails-data-hibernate5-core:codeStyle`, `codenarcTest` and `checkstyleTest`. The full module suites are left to CI. No user-facing change: this restores the 7.x behaviour, so no documentation change. ## Contributor Checklist ### Issue and Scope - [x] This PR is linked to an existing issue that has been **acknowledged or approved** by the project team. - [x] This PR addresses the **complete scope** of the linked issue. - [x] This PR contains a **single, focused change**. - [x] This PR targets the **correct branch** for the type of change: the regression first shipped in 8.0.0-M2 and `7.2.x` does not have it. ### Code Quality - [x] I have **added or updated tests** that cover the changes introduced in this PR. - [ ] I have verified that all existing tests pass by running `./gradlew build --rerun-tasks`. - [x] My code follows the project's **code style** guidelines. I have run `./gradlew codeStyle` and resolved any violations. - [x] This PR does **not** include mass reformatting, style-only changes, or large-scale refactoring. - [ ] If generative AI tooling was used in preparing this contribution, a quality model was used to ensure contributions are **consistent with the project's quality standards**. ### Licensing and Attribution - [x] All contributed code is provided under the Apache License 2.0, and new source files include the appropriate **Apache license header**. - [ ] I have the necessary rights to submit this contribution and confirm it is my own original work. - [ ] If generative AI tooling was used in preparing this contribution, I have followed the ASF policy on generative tooling and have properly attributed its use. ### Documentation - [x] The PR description clearly explains **what** was changed and **why**. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
