Take snapshot prior to mongo update then mark any changes during beforeUpdate and update events as dirty. #15143
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Hibernate overrides all dirty checking in the GormInstanceApi
https://github.com/apache/grails-core/blob/7.0.x/grails-data-hibernate5/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormInstanceApi.groovy#L77-L80
which uses hibernate's api for comparing against an internal snapshot.
Currently mongodb does not persist any updates during Events and AutoTimestamp events because the changes are not marked dirty and must be manually marked dirty.
https://grails.apache.org/docs/latest/grails-data/hibernate5/manual/index.html#eventsAutoTimestamping
This fix takes a snapshot before all events and then marks any changes as dirty props to persistence.