Open abcfy2 opened 5 years ago
I think this is related to this?
Yes, that's true. Since GORM 6.0.11 does not allow to modify dateCreated
, and I find the source code. If you changed the dateCreated, it will be dismissed.
https://gorm.grails.org/latest/hibernate/manual/index.html section 8.1.9
Make sure and flush the session is flushed inside the closure.
//Only the dateCreated property handling will be disabled for only the Foo domain
autoTimestampEventListener.withoutDateCreated(Foo) {
new Foo(dateCreated: new Date() - 1).save(flush: true)
}
//Only the lastUpdated property handling will be disabled for only the Foo and Bar domains
autoTimestampEventListener.withoutLastUpdated(Foo, Bar) {
new Foo(lastUpdated: new Date() - 1, bar: new Bar(lastUpdated: new Date() + 1)).save(flush: true)
}
//All timestamp property handling will be disabled for all domains
autoTimestampEventListener.withoutTimestamps {
new Foo(dateCreated: new Date() - 2, lastUpdated: new Date() - 1).save(flush: true)
new Bar(dateCreated: new Date() - 2, lastUpdated: new Date() - 1).save(flush: true)
new FooBar(dateCreated: new Date() - 2, lastUpdated: new Date() - 1).save(flush: true)
}```
Issue link: grails/grails-data-mapping#1249
When GORM version is greater than
6.1.11
, will nolonger to change thedateCreated
anymore.I find the reason is:
https://github.com/grails/gorm-hibernate5/blob/408b681658ee24ff13db3b6c20c9ea290756ec3b/grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/support/ClosureEventTriggeringInterceptor.java#L205-L208
I don't know why you're not allow to modify
dateCreated
?