I am trying to change a property of the domain object inside the beforeUpdate event. The problem is that the changed property does not reach the database. The domain class in question has the dymanicUpdate set to true. I noticed that if I change the dynamicUpdate to false the property gets persisted to the DB.
I created a simple Grails 3.2.9 project with GORM 6.0.11 with a single domain class.
class Example {
Integer status
Date dateCreated
Date dateClosed
Date lastUpdated
static constraints = {
status nullable: true
dateClosed nullable: true
}
static mapping = {
dynamicUpdate true
}
def beforeUpdate() {
if (isDirty('status')) {
dateClosed = new Date();
}
}
}
By default dynamicUpdate is set to false and the property I change in the beforeUpdate event gets persisted to the database. Although, if I switch the dynamicUpdate to true, the property changed in the beforeUpdate event is not persisted anymore to the database. Instead of the current date I get a null in the dateCreated column.
Any idea what is the reason for this behaviour and how to get the same result with the dynamicUpdate set to true?