Repository navigation
Mark to-one associations read-only after a validation error in Hibernate 7 - #16391
Merged
jdaugherty merged 1 commit intoSep 24, 2026
Merged
Conversation
…ate 7 `!association instanceof Embedded` parsed as `(!association) instanceof Embedded`, which is always false, so a failed save never marked the invalid instance's to-one associations read-only and their pending changes could still be flushed.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16391 +/- ##
==================================================
- Coverage 57.4441% 57.4413% -0.0029%
+ Complexity 22558 22555 -3
==================================================
Files 2129 2129
Lines 103840 103840
Branches 18646 18646
==================================================
- Hits 59650 59647 -3
- Misses 35929 35934 +5
+ Partials 8261 8259 -2 🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: dc5fe4f Learn more about TestLens at testlens.app/docs. |
jdaugherty
deleted the
fix/hibernate7-to-one-read-only-on-validation-error
branch
September 24, 2026 13:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
save()fails validation, the Hibernate 7HibernateGormInstanceApi.handleValidationErroris meant to mark the invalid instance and its to-one associations read-only, so a later flush in the same session cannot write them. The association check was written aswhich Groovy parses as
(!association) instanceof Embedded. That is always false, so only the instance itself was ever marked read-only. Unsaved changes on an associated object could still be flushed after the failed save.This is the Hibernate 7 counterpart of #16390 (7.0.x, Hibernate 5). The Hibernate 5 copy on
8.0.xwas already fixed in 153e14c. The Groovy 6 upgrade experiment (#16387) found the bug, since Groovy 6 rejects!x instanceof T, but the fix does not depend on Groovy 6.Changes
HibernateGormInstanceApi.handleValidationErroruses!(association instanceof Embedded), so non-embedded to-one associations are marked read-only as intended. Associations that are still unloaded proxies are left alone, as before.Testing
HibernateGormInstanceApiSpec:./gradlew clean aggregateViolations :grails-test-report:check --continuereports no Checkstyle, CodeNarc, PMD or SpotBugs violations. All Hibernate 7 module tests pass (3418 tests). The only failure in the full run was a 30-second fixture timeout ingrails-shell-cli'sSpringApplicationRunnerSpec, which passes when rerun on its own.