You can always initialize the field in the static initializer or set the value in the constructor:
class Something {
// initializer
Date myField = new Date()
// or in the ctor
Something() {
myField = new Date()
}
}
This doesn't set a default value in the database schema, it merely sets the value of the field on creation of the instance. If you want the schema to have a default value, you can use the 'defaultValue' mapping entry like so:
class Something {
Date myField
static mapping = {
myField defaultValue: "now()"
}
}
the value you set for the default value is dependent on your database vendor. (notice the use of sql now()
method rather than Java/Groovy new Date()
.