Grails: Building a Read-Only Domain Object

If you wish to create a read-only domain object that insure that no body is allowed to write to the database through your domain object, then add these even listener at the end of your domain object file:

transient beforeInsert = {
throw new RuntimeException('insert not allowed')

transient beforeUpdate = {
throw new RuntimeException('update not allowed')

transient beforeDelete = {
throw new RuntimeException('delete not allowed')


Leave a comment