Is there any way I can override the value of dateCreated
field in my domain class without turning off auto timestamping?
I need to test controller and I ha
You can try to disable it by setting autoTimestamp = false
in the domain class mapping. I doubt about global overriding because the value is taken directly from System.currentTimeMillis()
(I'm looking at org.codehaus.groovy.grails.orm.hibernate.support.ClosureEventListener.java).
So I can only suggest that you override a setter for dateCreated
field in your class, and assign your own value. Maybe even metaclass access will work, like
Date stubDateCreated
...
myDomainClass.metaClass.setDateCreated =
{ Date d -> delegate.@dateCreated = stubDateCreated }