Lifecycle Events
  • The supported lifecycle events are PrePersist, PostPersist, PreRemove, PostRemove, PreUpdate, PostUpdate, and PostLoad
  • An entity may define its own lifecycle callback methods (subclasses my override)
Callback Methods Example  
  @Entity
  public class EntityClass {
    ...
    @PrePersist
    public void validate() {
    }

    @PostLoad
    public void onLoad() {
    }
    ...
  }
  • An entity listener may be used to monitor lifecycle events
  • Entity listeners are invoked before entity callback methods (hierarchy is observed)
Entity Listener Example  
  • Entity listeners can be "excluded" by subclasses
Listener Exclusion Example