Events
Easily run actions on entity insertion, update, and more with event listeners
Last updated
Was this helpful?
Easily run actions on entity insertion, update, and more with event listeners
Last updated
Was this helpful?
Hibernate ORM allows reacting to various events in the session lifecycle such as onPreInsert
, onPostUpdate
, onFlush
, etc. You can enable event handling in CFML by setting eventHandling
to true
in your this.ormSettings
struct:
This will enable two different event listener types for listening to Hibernate events:
Listen to all events across all entities via the
Listen to specific events on a specific entity via methods
To use a global event handler, you must set a path to the global event handler using the eventHandler
setting:
The EventHandler.cfc
must then contain function definitions matching the ORM events you wish to listen for.
Currently, the available event names are:
onFlush
preLoad
postLoad
preInsert
postInsert
preUpdate
postUpdate
preDelete
onDelete
postDelete
onEvict
onClear
onDirtyCheck
onAutoFlush
Here's an example of an EventHandler configured for all events:
You can also listen to events on a specific entity at the entity level by adding methods to the entity (component) itself:
Here is the full list of event types which can be listened to in entity event listeners:
preLoad
postLoad
preInsert
postInsert
preUpdate
postUpdate
preDelete
onDelete
postDelete