matrei opened a new pull request, #16504: URL: https://github.com/apache/grails-core/pull/16504
## Description `HibernateSession.setFlushMode(FlushModeType)` changed the flush mode of the `GrailsHibernateTemplate` that the `HibernateDatastore` caches and shares. Every `HibernateSession` wrapper uses that one template, so a flush mode set through one GORM session: - applied to the template operations of every session and thread of the datastore, such as `get`, `save`, `delete` and HQL queries - stayed in place until something set it again - also changed whether those operations flush eagerly outside a transaction `getFlushMode()` reported any flush mode but COMMIT as AUTO, so saving and restoring the mode turned a configured MANUAL or ALWAYS into AUTO. No framework code calls these methods on Hibernate 7: the validation API, persistence context interceptor, open session in view and transaction manager that would are overridden or not wired for Hibernate 7. User or plugin code reaches them through `datastore.currentSession` or the session passed by `Tenants.withId`. Both methods now use the Hibernate session bound to the current thread, which is what the flush mode of a GORM session means on other datastores: - `setFlushMode` sets the flush mode of that session. The template and other sessions are not changed. - `getFlushMode` returns the flush mode of that session. Hibernate reports MANUAL as COMMIT and ALWAYS as AUTO, since `FlushModeType` has only those two values. - Without a bound session, `getFlushMode` returns the default flush mode of the datastore and `setFlushMode` throws an `IllegalStateException`. Hibernate 5 is not affected: each of its `HibernateSession` wrappers builds its own template, so a flush mode set on one cannot reach other sessions. ### Tests `HibernateSessionSpec`: `getFlushMode and setFlushMode round-trip correctly` only checked that the value read back matched the value set, which the shared template also satisfied. It is replaced by tests that: - `setFlushMode` changes the flush mode of the bound Hibernate session - `setFlushMode` leaves the flush mode of the template the datastore shares unchanged - `getFlushMode` returns AUTO for a bound session in AUTO or ALWAYS, and COMMIT for one in COMMIT or MANUAL - on a thread without a bound session, `getFlushMode` returns the datastore default and `setFlushMode` throws `IllegalStateException` Without the change, 5 of these 8 cases fail, including the one showing the shared template being changed. All 3483 tests of `:grails-data-hibernate7-core:test` pass, and so do `checkstyleMain` and `codenarcMain`. -- 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]
