joemccall86 opened a new issue, #14493: URL: https://github.com/apache/grails-core/issues/14493
We're trying to capture any failed validations for GORM objects created in a batch job, and persisting those as GORM objects. Ultimately we found that any validation error that occurred set the session flush mode from COMMIT to MANUAL, which was surprising. In searching for the desired behavior, I saw an inconsistency. * https://github.com/grails/grails-data-mapping/blob/aab03ddb501e8ad33568403c7f59a816c9d3ee62/grails-datastore-gorm/src/main/groovy/org/grails/datastore/gorm/GormValidationApi.groovy#L139 the previous flush mode is preserved in all cases * https://github.com/grails/gorm-hibernate5/blob/14cf71464f8118d84c4732e0990951ef48b84264/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/AbstractHibernateGormValidationApi.groovy#L91 the previous flush mode is only preserved if the object passed validation. So which is the intended behavior? Personally I wouldn't expect the validate() method to permanently change the flush mode for the session, but there may be some use case I'm not considering. ### Task List - [x] Steps to reproduce provided - [x] Stacktrace (if present) provided - [x] Example that reproduces the problem uploaded to Github - [x] Full description of the issue provided (see below) ### Steps to Reproduce 1. Validate an invalid GORM object from within a transaction ### Expected Behaviour The flush mode of the session stays as COMMIT ### Actual Behaviour The flush mode of the session is changed to MANUAL ### Environment Information - **Operating System**: Fedora Linux 33 - **GORM Version:** 7.0.6.RELEASE - **Grails Version (if using Grails):** 4.0.5 - **JDK Version:** ``` openjdk version "1.8.0_265" OpenJDK Runtime Environment Corretto-8.265.01.1 (build 1.8.0_265-b01) OpenJDK 64-Bit Server VM Corretto-8.265.01.1 (build 25.265-b01, mixed mode) ``` ### Example Application - https://github.com/joemccall86/session-flush-mode-test -- 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]
