- Type Parameters:
ENTITY- the entity type this listener operates on
- All Known Implementing Classes:
NullEntityListener
This interface defines methods that are called before and after entity persistence operations (insert, update, delete). Entity listeners can be used to implement cross-cutting concerns such as validation, auditing, or setting default values.
Entity listeners are associated with entity classes using the Entity.listener() attribute.
The implementation class must have a public no-arg constructor.
The implementation class must be thread safe.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidpostDelete(ENTITY entity, PostDeleteContext<ENTITY> context) Called after an entity has been successfully deleted from the database.default voidpostInsert(ENTITY entity, PostInsertContext<ENTITY> context) Called after an entity has been successfully inserted into the database.default voidpostUpdate(ENTITY entity, PostUpdateContext<ENTITY> context) Called after an entity has been successfully updated in the database.default voidpreDelete(ENTITY entity, PreDeleteContext<ENTITY> context) Called before an entity is deleted from the database.default voidpreInsert(ENTITY entity, PreInsertContext<ENTITY> context) Called before an entity is inserted into the database.default voidpreUpdate(ENTITY entity, PreUpdateContext<ENTITY> context) Called before an entity is updated in the database.
-
Method Details
-
preInsert
Called before an entity is inserted into the database.This method allows implementing pre-insert logic such as setting creation timestamps, generating IDs, or validating entity state.
- Parameters:
entity- the entity instance about to be insertedcontext- the context containing information about the insert operation- See Also:
-
preUpdate
Called before an entity is updated in the database.This method allows implementing pre-update logic such as setting modification timestamps, validating entity state, or implementing business rules that must be enforced before updates.
- Parameters:
entity- the entity instance about to be updatedcontext- the context containing information about the update operation- See Also:
-
preDelete
Called before an entity is deleted from the database.This method allows implementing pre-delete logic such as validating that the entity can be deleted, logging deletion attempts, or implementing business rules that must be enforced before deletions.
- Parameters:
entity- the entity instance about to be deletedcontext- the context containing information about the delete operation- See Also:
-
postInsert
Called after an entity has been successfully inserted into the database.This method allows implementing post-insert logic such as processing generated IDs, triggering related operations, or performing additional validations after the insert operation.
- Parameters:
entity- the entity instance that was insertedcontext- the context containing information about the insert operation- See Also:
-
postUpdate
Called after an entity has been successfully updated in the database.This method allows implementing post-update logic such as triggering related operations, performing additional validations, or executing business logic that depends on the updated state.
- Parameters:
entity- the entity instance that was updatedcontext- the context containing information about the update operation- See Also:
-
postDelete
Called after an entity has been successfully deleted from the database.This method allows implementing post-delete logic such as cleaning up related resources, triggering cascading operations, or logging successful deletions for audit purposes.
- Parameters:
entity- the entity instance that was deletedcontext- the context containing information about the delete operation- See Also:
-