Repository navigation
Mark to-one associations read-only after a validation error - #16390
Merged
jdaugherty merged 1 commit intoSep 24, 2026
Merged
Conversation
`!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.
✅ All tests passed ✅Test SummaryCI / Build Grails Forge (17) > :grails-forge-cli:test [grails-forge]
🏷️ Commit: 9416da6 Test FailuresCreateControllerCommandSpec > test app with controller (:grails-forge-cli:test [grails-forge] in CI / Build Grails Forge (17) | Attempt 2/3)CreateControllerCommandSpec > test app with controller (:grails-forge-cli:test [grails-forge] in CI / Build Grails Forge (17) | Attempt 1/3)Learn more about TestLens at testlens.app/docs. |
This was referenced Sep 24, 2026
jdaugherty
deleted the
fix/hibernate-to-one-read-only-on-validation-error
branch
September 24, 2026 14:19
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 5handleValidationErroris 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.The Groovy 6 upgrade experiment (#16387) found this: Groovy 6 rejects
!x instanceof T. The fix does not depend on Groovy 6, so it is submitted separately here.Changes
AbstractHibernateGormInstanceApi.handleValidationErroruses!(association instanceof Embedded), so non-embedded to-one associations that are already loaded are marked read-only as intended. Associations that are still unloaded proxies are left alone, as before.Testing
New
ValidationErrorToOneReadOnlySpecingrails-data-hibernate5-core::grails-data-hibernate5-core:testpasses (601 tests, 0 failures) and so does./gradlew codeStyle.Follow-up
On
8.0.xthe Hibernate 5 copy is already fixed, so the merge-up only brings this spec along. The same check in the Hibernate 7HibernateGormInstanceApineeds its own PR against8.0.x.