matrei opened a new pull request, #16391:
URL: https://github.com/apache/grails-core/pull/16391

   ## Summary
   
   When `save()` fails validation, the Hibernate 7 
`HibernateGormInstanceApi.handleValidationError` is 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 as
   
   ```groovy
   if (association instanceof ToOne && !association instanceof Embedded) {
   ```
   
   which 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.x` was already fixed in 153e14c5ad. 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.handleValidationError` uses `!(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`:
   
   - The existing feature "handleValidationError sets association to read-only" 
only checked that the save failed, so it passed with the bug. It now gives a 
saved author an unsaved rename, fails validation on a book referencing it, and 
checks that the author is read-only and that an explicit flush and reload leave 
its name unchanged. It fails without the fix.
   - New feature: when the author is an unloaded proxy, the failed save does 
not load it.
   
   `./gradlew clean aggregateViolations :grails-test-report:check --continue` 
reports 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 in `grails-shell-cli`'s 
`SpringApplicationRunnerSpec`, which passes when rerun on its own.
   


-- 
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]

Reply via email to