Adding Lifecycle hooks into your Onyx Database Entities

Adding event driven triggers and hooks is easy with Onyx Database.

Below is listed a comprehensive set of event listeners that Onyx provides. Each listener is configured by adding a method within the entity that is enabled by adding an annotation above the method.

Annotation Lifecycle Event Description

@PreInsert

A method annotated with @PreInsert is executed prior to inserting an entity. This gives you the capability to modify or auto generate attributes. An example would be an attribute to indicate dateInserted.

@PrePersist

@PrePersist is much like @PreInsert except it will execute on both insert and update. Basically anytime you save that entity.

@PreUpdate

Invoked upon updating an already existing entity.

@PostInsert

Will be invoked after an entity has been inserted. If you make alterations to said entity, they will not be represented in the persistence store.

@PostPersist

Similar to @PostInsert except it does not just key on insert. It also keys off of update.

@PostUpdate

Invoked upon after updating an entity.

@PostRemove

After deleting an entity, post insert methods will be invoked. This gives you the ability to run any last business logic after the entity goes away.
Using lifecycle events
An entity workflow using lifecycle events.
Here is an example of using the @PreInsert, @PreUpdate, @PostRemove lifecycle events to demonstrate how to perform heuristic data manipulation.