matrei opened a new pull request, #16501: URL: https://github.com/apache/grails-core/pull/16501
## Description Fixes two bugs in `grails-data-hibernate5` and removes a resource file that Hibernate never loads. Each change and its tests are in their own commit. The same code is in `grails-data-hibernate7` on 8.0.x, which a merge-up does not touch, so the Hibernate 7 copies are fixed separately. ### `@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 Javadoc of `AbstractHibernateDatastore.withFlushMode` describes 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`: an entity with `mapWith` set to `'hibernate'` or `'GORM'` is transformed, and one set to `'mongo'` is not. - `HibernateDatastoreSpec`: `withFlushMode` applies the flush mode while the callable runs, and restores the previous mode when the callable returns `true` or `null` but not when it returns `false`. A runtime exception from the callable is rethrown as is, a checked one wrapped in `UndeclaredThrowableException`, and in both cases the previous mode is restored. The 5 tests aimed at the bugs fail without the fixes. The `'mongo'`, `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-hibernate5-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]
