matrei opened a new pull request, #16502: URL: https://github.com/apache/grails-core/pull/16502
## Description The Hibernate 7 counterpart of #16501, which fixes the same code in `grails-data-hibernate5`. A merge-up of 7.0.x does not touch `grails-data-hibernate7`, so these copies are fixed here. Each change and its tests are in their own commit. ### `@ManagedEntity` skipped entities with `mapWith = 'hibernate'` `HibernateEntityTransformation` returned early when ```groovy mapWithValue != null && (mapWithValue != 'hibernate' || mapWithValue != 'GORM') ``` No value equals both, so the condition was true for any `mapWith`. An entity annotated with `@ManagedEntity` and declaring `static mapWith = 'hibernate'` (or `'GORM'`) was left untransformed: it did not implement Hibernate's `ManagedEntity` and `PersistentAttributeInterceptable`. The transformation now skips only an entity mapped with another datastore. ### `HibernateDatastore.withFlushMode` swallowed exceptions An exception thrown by the callable was caught and discarded, and the previous flush mode was then left unrestored. A callable returning `null` caused a `NullPointerException` while the previous mode was being restored. The exception is now rethrown after the previous flush mode is restored. A checked exception is wrapped in an `UndeclaredThrowableException`, as Spring's `ReflectionUtils.rethrowRuntimeException` does. As before, the previous flush mode is kept only when the callable returns `false`; `null` now restores it like `true`. The method has a Javadoc describing this. ### Remove `META-INF/org.hibernate.integrator.spi.Integrator` The file names `EventListenerIntegrator` but is not under `META-INF/services/`, so Hibernate never reads it. It has to stay unread: `EventListenerIntegrator` has no no-arg constructor, so Hibernate could not create it through `ServiceLoader`. `HibernateMappingContextConfiguration` already registers it through `BootstrapServiceRegistryBuilder.applyIntegrator`. ### Tests - `HibernateEntityTransformationSpec`: the test that an entity with `mapWith = "mongodb"` is not transformed now also checks that one with `'hibernate'` or `'GORM'` is. - `HibernateDatastoreSpec`: `test withFlushMode does not restore mode when callable throws` asserted the old behaviour. It is replaced by tests that a runtime exception from the callable is rethrown as is and a checked one wrapped in `UndeclaredThrowableException`, with the previous mode restored in both cases, and that the previous mode is restored when the callable returns `true` or `null` but not when it returns `false`. The 5 tests aimed at the bugs fail without the fixes. The `'mongodb'`, `true` and `false` cases pass with or without them. The removed Integrator file has no test of its own. The existing GORM event tests in `:grails-data-hibernate7-core:test` cover the listeners that `EventListenerIntegrator` registers. -- 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]
