dateCreated, lastUpdated fields in Grails 2.0

srkiNZ84 picture srkiNZ84 · Jan 29, 2012 · Viewed 23.6k times · Source

I've got an application that was using Grails 1.3.7 which I've just migrated to Grails 2.0. The application makes use of the automatic dateCreated and lastUpdated fields to manage the timestamps associated with creation and modification of the objects. After upgrading, I get the following error:

| Running Grails application
| Error 2012-01-29 22:36:53,504 [Thread-8] ERROR util.JDBCExceptionReporter  - ERROR: null value in column "date_created" violates not-null constraint
| Error 2012-01-29 22:36:53,510 [Thread-8] ERROR events.PatchedDefaultFlushEventListener  - Could not synchronize database state with session

Commenting out the above mentioned fields in my Domain Classes makes the problem go away.

Have the dateCreated and lastUpdated fields been deprecated in Grails 2.0? If so, does that mean that I have to write the code to handle this functionality manually or has the code been moved to a plugin of some sort, like the audit-trail plugin?

Answer

srkiNZ84 picture srkiNZ84 · Jan 30, 2012

Ok, fixed it by manually setting the autoTimestamp variable to "true" in the domain class definitions:

static mapping = {
        autoTimestamp true
}

I would guess that this property is not set after migrating a project from Grails 1.3.7 to 2.0.0.