This will serve as documentation for the Hibernate Events plugin. The Hibernate Events plugin adds support to domain models for hooking into the hibernate event system using the following methods: afterInsert, afterUpdate, afterDelete, beforeLoad, afterLoad, beforeSave, and afterSave. Domain models implementing these methods will have the method called during it's phase of the lifecycle. beforeSave and afterSave will be called on either insert or update persistence calls. the impetus for this plugin was that fact that there are currently only three persistence lifecycle events handled by grails by default: beforeInsert, beforeUpdate, and beforeDelete.A word of warning (version 0.1 only): The plugin uses a hibernate.cfg.xml file to declare the event listener, because it is the only way currently to participate in the construction of the hibernate sessionFactory. I can't say for sure, because I don't use a hibernate config file in my app, but I'm pretty sure that you will have to merge this file in with your file to use the plugin if you currently have a hibernate.cfg.xml file on your classpath.
Installation
From your project root:grails install-plugin http://thegioraproject.com/files/grails/plugins/grails-hibernate-events-0.3.zip
Usage
You can then have a class such as this and the closures will be invoked during the persistence lifecycle:class Model {
String something def beforeLoad = {
println "I was invoked after the database query, but before the object was populated"
}
def afterLoad = {
println "I was invoked after the object was populated"
}
def beforeSave = {
println "I was invoked before an update or a save"
}
def afterSave = {
println "I was invoked after an object was saved or updated"
}
def beforeInsert = {
println "I was invoked before the object was saved for the first time"
}
def afterInsert = {
println "I was invoked after the object was saved for the first time"
}
def beforeUpdate = {
println "I was invoked before the object was resaved"
}
def afterUpdate = {
println "I was invoked after the object was resaved"
}
def beforeDelete = {
println "I was invoked before the object was deleted"
}
def afterDelete = {
println "I was invoked after the object was deleted"
}
}


