jamesfredley commented on code in PR #16651:
URL: https://github.com/apache/grails-core/pull/16651#discussion_r4341193351


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormValidationApi.groovy:
##########
@@ -108,9 +108,7 @@ class HibernateGormValidationApi<D> extends 
GormValidationApi<D> {
                     validator.validate instance, errors
                 }
             } finally {
-                if (!errors.hasErrors()) {
-                    session.setHibernateFlushMode(previous)
-                }
+                session.setHibernateFlushMode(previous)

Review Comment:
   This restore runs before the error handling below, and it runs even when 
validation failed. A managed instance that failed `validate()` is still dirty 
and attached. Restoring AUTO or COMMIT makes the next same-table query, or the 
transaction commit, flush it. `doValidate()` then throws `ValidationException` 
and rolls back unrelated writes.
   
   Keep MANUAL, or evict, for a failed managed instance before restoring 
automatic flushing. Restore immediately for an unattached instance and for a 
successful validation. Do the same in the Hibernate 5 API. Please add a 
regression with `failOnError=true`: an invalid managed entity, a following 
query or commit, and an assertion that the transaction is not failed by that 
flush.



-- 
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]

Reply via email to