matrei opened a new pull request, #16424: URL: https://github.com/apache/grails-core/pull/16424
Fixes #16423 ## Problem `HibernateEntityTransformation` added the `$$_hibernate_instanceId` field with an initial value of `-1`. Hibernate 7 asserts that an entity not yet associated with a persistence context has an instance id of `0` (`EntityEntryContext#addEntityEntry`). Saving a new `@ManagedEntity` instance therefore failed with an `AssertionError` whenever JVM assertions were enabled. Gradle `Test` tasks 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 returns `0` from `$$_hibernate_getInstanceId()` and has no entity entry or linked managed entities. - New `ManagedEntitySaveSpec`: saves a single `@ManagedEntity` instance, and several in one session, then reads them back. With the `-1` initialiser restored, all three new features fail: the two save features with the `AssertionError` from `EntityEntryContext.addEntityEntry`, and the transformation feature on the instance id. ## Verification - `:grails-data-hibernate7-core:test`: 3296 tests, 0 failures (29 skipped) - CodeNarc and Checkstyle for `grails-data-hibernate7-core`: pass The Hibernate 5 transformation has no instance id field and is not affected. -- 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]
