matrei opened a new pull request, #16503: URL: https://github.com/apache/grails-core/pull/16503
## Description `AbstractHibernateDatastore` keeps its default flush mode as `FlushMode.level`: MANUAL 0, COMMIT 5, AUTO 10 and ALWAYS 20. That value was passed as is to every `GrailsHibernateTemplate` it creates, and to the templates of the GORM static, instance and validation APIs, through `new GrailsHibernateTemplate(sessionFactory, datastore)` and `getHibernateTemplate()`. The template compares its flush mode with its `FLUSH_*` constants, which run from 0 to 4. Only MANUAL matched, because both use 0. For every other configured `hibernate.flush.mode`, the template ignored it: - With COMMIT (the default) or ALWAYS, template operations such as `get`, `save`, `delete` and HQL queries did not apply the configured mode to the session. - `HibernateSession.getFlushMode()` returned AUTO for COMMIT. The templates now get the matching `FLUSH_*` constant, as on Hibernate 7. The Javadoc of `getHibernateTemplate(int)` now says that it takes one of those constants. ### Behaviour change In a transaction, a template operation now runs with the configured flush mode: a session in AUTO or ALWAYS is switched to COMMIT for the operation when COMMIT is configured, and gets its mode back afterwards. Sessions that GORM opens, through its transaction manager or open session in view, already use the configured mode, so this affects only a session whose flush mode application code has changed. Outside a transaction, a template operation sets the configured mode on the bound session and leaves it there, as it already did for MANUAL. ### Tests New `GrailsHibernateTemplateFlushModeSpec`, for each `hibernate.flush.mode`: - the datastore's template and a template created for the datastore use the matching `FLUSH_*` constant - in a transaction whose session is in AUTO, a template operation runs with the configured mode, and the session is back in AUTO afterwards - `HibernateSession.getFlushMode()` returns the configured COMMIT or AUTO Without the change, 6 of the 10 cases fail. The MANUAL cases and the AUTO operation case pass either way. All tests of `:grails-data-hibernate5-core:test` and `:grails-data-hibernate5: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]
