chrisbrookes opened a new issue, #14354: URL: https://github.com/apache/grails-core/issues/14354
I'm trying to manage updates to a domain object through different controller actions with the object stored in the session. At the end of the editing I'm doing a merge to push the changed fields of the object to the datastore. The merge completes without error but the changes are not sent to the database. I've reproduced with a simple project - [grailsMergeBug-bug-report-01112022.zip](https://github.com/grails/gorm-hibernate5/files/9909773/grailsMergeBug-bug-report-01112022.zip). Go to http://localhost:8080/data to reproduce. The domain object looks like this: ``` package grailsmergebug import groovy.transform.ToString @ToString(includePackage = false, includes = ['name', 'number'], includeNames = true) class Data { String name Integer number static constraints = {} } ``` Changes to the `name` or `number` fields do not get merge saved. I've simulated the editing, storing in session and merge in a controller: ``` ... @Transactional def index() { Data.deleteAll([flush: true], Data.list()) Data data = new Data(name: "data1", number: 1) data.save() redirect(action: 'putInSession') } def putInSession() { Data data = Data.list().first() data.name = "dirtied" data.number += 1 logDirtyStatus(data, "putInSession") session.data = data redirect(action: 'tryMerge') } @Transactional def tryMerge() { Data data = session.data logDirtyStatus(data, "tryMerge") log.debug "doing merge..." def mergeRet = data.merge(failOnError: true, flush: true) log.debug "merge return data: $data" session.data = null redirect(action: 'checkSaved') } def checkSaved() { Data data = Data.list().first() log.debug "checkSaved data: $data" render "$data -- ${data.name == 'dirtied' ? 'changed OK' : 'did not merge the changes'}" } private def logDirtyStatus(Data data, String prefix) { log.debug "[$prefix] val: $data.name | hasChanged: ${data.hasChanged()} | hasChanged(field): ${data.hasChanged("name")} | " + "list dirty: ${data.listDirtyPropertyNames()} | get dirty: ${data.getDirtyPropertyNames()} | " + "dirty: ${data.dirty} | dirty(field): ${data.isDirty("name")}" } ... ``` Going to checkSaved action in a browser shows that the object has not been updated. Versions: ``` grailsVersion=5.2.3 grailsGradlePluginVersion=5.2.3 groovyVersion=3.0.11 gorm.version=7.3.2 ``` -- 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]
