Interface EntityListener<ENTITY>

Type Parameters:
ENTITY - the entity type this listener operates on
All Known Implementing Classes:
NullEntityListener

public interface EntityListener<ENTITY>
A callback listener interface that is invoked during entity lifecycle events.

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 Details

    • preInsert

      default void preInsert(ENTITY entity, PreInsertContext<ENTITY> context)
      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 inserted
      context - the context containing information about the insert operation
      See Also:
    • preUpdate

      default void preUpdate(ENTITY entity, PreUpdateContext<ENTITY> context)
      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 updated
      context - the context containing information about the update operation
      See Also:
    • preDelete

      default void preDelete(ENTITY entity, PreDeleteContext<ENTITY> context)
      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 deleted
      context - the context containing information about the delete operation
      See Also:
    • postInsert

      default void postInsert(ENTITY entity, PostInsertContext<ENTITY> context)
      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 inserted
      context - the context containing information about the insert operation
      See Also:
    • postUpdate

      default void postUpdate(ENTITY entity, PostUpdateContext<ENTITY> context)
      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 updated
      context - the context containing information about the update operation
      See Also:
    • postDelete

      default void postDelete(ENTITY entity, PostDeleteContext<ENTITY> context)
      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 deleted
      context - the context containing information about the delete operation
      See Also: