Repository navigation
Start @ManagedEntity instance id at 0 for Hibernate 7 - #16424
Merged
jdaugherty merged 1 commit intoSep 29, 2026
Merged
Conversation
HibernateEntityTransformation initialised $$_hibernate_instanceId to -1. Hibernate 7 asserts that an entity not yet associated with a persistence context has an instance id of 0, so saving a new @ManagedEntity instance failed with an AssertionError whenever JVM assertions were enabled, which Gradle test tasks do by default. Add the field without an initial value, matching Hibernate's own bytecode enhancer and the other fields added by the transformation. Fixes apache#16423
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16424 +/- ##
==================================================
+ Coverage 58.4944% 58.5047% +0.0103%
- Complexity 24184 24188 +4
==================================================
Files 2175 2175
Lines 107176 107176
Branches 19515 19515
==================================================
+ Hits 62692 62703 +11
+ Misses 35641 35627 -14
- Partials 8843 8846 +3 🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: c262e97 Learn more about TestLens at testlens.app/docs. |
jdaugherty
approved these changes
Sep 29, 2026
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.
Fixes #16423
Problem
HibernateEntityTransformationadded the$$_hibernate_instanceIdfield with an initial value of-1. Hibernate 7 asserts that an entity not yet associated with a persistence context has an instance id of0(EntityEntryContext#addEntityEntry). Saving a new@ManagedEntityinstance therefore failed with anAssertionErrorwhenever JVM assertions were enabled. GradleTesttasks enable them by default, so any integration test whose application saved such an entity at startup failed to load its context.With assertions disabled, Hibernate overwrites the value through
$$_hibernate_setPersistenceInfo(...)as soon as the entity is associated, so production behaviour was not visibly affected.Change
The field is now added without an initial value, so it starts at
0. This matches Hibernate's own bytecode enhancer and the other fields the transformation adds.Tests
HibernateEntityTransformationSpec: a new instance returns0from$$_hibernate_getInstanceId()and has no entity entry or linked managed entities.ManagedEntitySaveSpec: saves a single@ManagedEntityinstance, and several in one session, then reads them back.With the
-1initialiser restored, all three new features fail: the two save features with theAssertionErrorfromEntityEntryContext.addEntityEntry, and the transformation feature on the instance id.Verification
:grails-data-hibernate7-core:test: 3296 tests, 0 failures (29 skipped)grails-data-hibernate7-core: passThe Hibernate 5 transformation has no instance id field and is not affected.