Skip to content

Restore Hibernate validation error-reset semantics - #16489

Merged
jdaugherty merged 2 commits into
apache:8.0.xfrom
jdaugherty:fix/hibernate-validation-error-reset
Oct 3, 2026
Merged

jdaugherty merged 2 commits into
apache:8.0.xfrom
jdaugherty:fix/hibernate-validation-error-reset

Conversation

@jdaugherty

Copy link
Copy Markdown
Contributor

Summary

Restore Grails 7’s Hibernate validation error-reset behavior in both the Hibernate 5 and Hibernate 7 integrations.

At the start of validation:

  • Preserve existing field errors marked as binding failures.
  • Clear previously added global errors and non-binding field errors.
  • Continue honoring errors raised during the current validation by constraints and beforeValidate callbacks.

Background

Commit e53dfd9 changed Hibernate’s error initialization to copy existing global errors into the new errors object.

Previously, Hibernate validation discarded those global errors. Consequently, existing application code that adds a global error with errors.reject(...) can behave differently after upgrading: subsequent validation, saves, or dirty-entity flushes retain that error and fail, even when the entity satisfies its constraints.

This PR restores the previous Hibernate behavior. Other GORM datastores retain their existing semantics.

Changes

  • Restore binding-failure-only copying in both Hibernate implementations.
  • Update the shared TCK to explicitly test the datastore-specific behavior.
  • Add matching Hibernate 5 and Hibernate 7 regression coverage for:
  • validate(), map arguments, and field-list arguments.
  • Explicit saves and dirty-entity flushes.
  • Existing global and non-binding field errors.
  • Preservation of binding-error details.
  • Constraint failures and newly raised beforeValidate errors.
  • Document the Hibernate error-reset lifecycle in the validate() reference.
    Verification
  • Reproduced the behavior difference using identical real Hibernate/H2 tests against Grails 7.2.4 and the unpatched Grails 8 snapshot.

@codecov

codecov Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.3681%. Comparing base (80a1ff5) to head (5288a8d).
⚠️ Report is 20 commits behind head on 8.0.x.

Files with missing lines Patch % Lines
...rails/data/testing/tck/tests/ValidationSpec.groovy 66.6667% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##                8.0.x     #16489        +/-   ##
==================================================
+ Coverage     59.2827%   59.3681%   +0.0855%     
- Complexity      24770      24829        +59     
==================================================
  Files            2170       2171         +1     
  Lines          108121     108186        +65     
  Branches        19709      19729        +20     
==================================================
+ Hits            64097      64228       +131     
+ Misses          35147      35031       -116     
- Partials         8877       8927        +50     
Files with missing lines Coverage Δ
...a/testing/tck/tests/ValidationHibernateSpec.groovy 98.5577% <100.0000%> (ø)
...rails/data/testing/tck/tests/ValidationSpec.groovy 96.7213% <66.6667%> (-0.7994%) ⬇️

... and 15 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

This comment has been minimized.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved.

Hibernate 5 and Hibernate 7 again copy only binding-failure field errors at the start of validation. Previous global errors and ordinary field errors are cleared. Errors raised during the current validation, including beforeValidate, still fail the save. The shared GORM validation API is unchanged, and the TCK still requires other datastores to retain global errors.

CI on 185ab62 passed the new regression cases on both Hibernate 5 and Hibernate 7, plus the modified TCK assertions.

Add a Hibernate 5 spec that calls setupErrorsProperty directly, and extend
the Hibernate 7 spec, covering global errors, mixed error types, binding
failure details, and non-GormValidateable targets.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@borinquenkid borinquenkid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. I pushed one commit (5288a8d) that only expands test coverage: a Hibernate 5 spec that calls setupErrorsProperty directly, and two extra cases in the Hibernate 7 HibernateRuntimeUtilsSpec (global errors not copied, a mix of error types). There are no production changes and I found no bugs. The full Hibernate 5 and 7 core suites pass.

@jdaugherty
jdaugherty merged commit 657556a into apache:8.0.x Oct 3, 2026
82 checks passed
@jdaugherty
jdaugherty deleted the fix/hibernate-validation-error-reset branch October 3, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants