Grails’ dateCreated and lastUpdated properties

 

 

I’m in the process of learning Groovy and Grails, and Grails has this neat feature called scaffolding where you just create a domain class like a User and all its properties, and it’s auto-create a full CRUD to be able to create/read/update/and delete.

class User
{
	String userId
 	String password
	Date dateCreated
	Date coolStuff
	Profile profile
}

Which when creating, will generate a form like this:

 

 

 

 

 

 

But I was wondering what’s the deal with dateCreated. Turns out that if you define dateCreated and lastUpdated properties, Grails will automatically take care of storing in the database the record creation date and when it was last updated (which is all facilitated via Grails’ ORM Hibernate wrapper).

 

 

Written by Tariq Ahmed