Skip to content

Spring Boot

Listening to events in SpringBoot

Jotting down some examples of different ways to handle events in Spring Boot

Entity Lifecycle

Entities, i.e. pojos annotated with @Entity, can utilize the following methods with annotations to manage life cycle events of the entity. JPA defines several lifecycle events that occur during an entity's persistence operations. You can use annotations to specify methods that should be executed when these events occur.

  • @PrePersist: Called before the entity is persisted (inserted into the database).
  • @PostPersist: Called after the entity is persisted.
  • @PreUpdate: Called before the entity is updated in the database.
  • @PostUpdate: Called after the entity is updated.
  • @PreRemove: Called before the entity is removed from the database.
  • @PostRemove: Called after the entity is removed.
  • @PostLoad: Called after the entity is loaded from the database.