grails delete all data from table / domain class, i.e. "deleteAll"

Ray picture Ray · Nov 17, 2011 · Viewed 20.8k times · Source

I've got a domain class, Widget, that I need to delete all instances out of -- clear it out. After that, I will load in fresh data. What do you suggest as a mechanism to do this?

P.S. Note this is not at bootstrap time, but at "run-time".

Answer

ataylor picture ataylor · Nov 17, 2011

The easiest way is to use HQL directly:

DomainClass.executeUpdate('delete from DomainClass')