The complaint: Grails 4.0.10, Gorm 7.0.8.RELEASE does not set the domain class isDirty flag in all cases, and therefore no update is performed to the backend.
In Grails 3 I have for years had working code in a filter that handles token logins. Upon success this code is executed:
User.withTransaction {
User user = User.get(userDetails.id)
Date now = new Date();
user.loginSuccess(now, userDetails.ipAddr, idno, true)
}
The User.loginSucess() method is this:
void loginSuccess(Date when, String ipAddr, String idno = null, boolean flush = false) {
lastLoginDate = loginDate
loginDate = when.toTimestamp()
lastUpdated = when.toTimestamp()
lastLoginIp = loginIp
loginIp = ipAddr
loginFailedCount = 0
firstFailedDate = null
idno = idno
save(flush: flush, validate: false)
}
This code never updates the database, regardless of the state of the flush flag, unless I trigger isDirty somehow. I do it by changing
lastUpdated = when.toTimestamp()
to
this.setLastUpdated(when.toTimestamp())
This peculiar nature of setting the dirty flag existed years ago in Grails 2. Is this different behavior expected and an oversight on my part? (The User.lastUpdated property is nothing special - a Date field mapped as sqlType: 'Timestamp' for writing to Postgres.)
Taking JSB's comment as the explanation of the behavior, and the answer.