I guess events can help to solve your problem. Take a look at beforeUpdate.
Grails domain object derived property not updated after save
-
14-04-2022 - |
题
I am using a derived field in Grails domain class:
BigDecimal expectedDurationHrs
static mapping = {
expectedDurationHrs formula: 'time_to_sec(timediff(expected_end_date, expected_start_date )) / 3600'
}
This allows me to query for this duration. The problem is that when I make a change to the start or end date the derived property does not get updated even after .save(flush: true)
is called.
I would have expected after the save that the derived propert be updated. Similarly the domain instance stored in the Hibernate cache does not have the correct derived value.
Is there a way to have this refreshed and return the latest value?
cowper
解决方案
不隶属于 StackOverflow