Lifecycle Methods

The lifecycle callback methods notify a domain entity about its interaction within the persistence lifecycle. For example, the entity is notified immediately prior to being persisted, or when it is about to be updated.

The lifecycle callback methods supported by Apache Causeway are:

Table 1. Lifecycle methods (partial support)
Method Description Event
equivalent

created()

called when an object has just been created using FactoryService#create(..) or RepositoryService#detachedEntity(…​)

ObjectCreatedEvent

loaded()

called when a (persistent) object has just been loaded from the object store.

ObjectLoadedEvent

persisted()

called when object has just been persisted from the object store.

ObjectPersistedEvent

persisting()

called when a (not-yet-persistent) object is just about to be persisted from the object store

ObjectPersistingEvent

removing()

called when a (persistent) object is just about to be deleted from the object store

ObjectRemovingEvent

updated()

called when a (persistent) object has just been updated in the object store

ObjectUpdatedEvent

updating()

called when a (persistent) object is just about to be updated in the object store

ObjectUpdatingEvent

Further discussion on using events and a subscriber (which will result in a more flexible/decoupled design) can be found here.

created()

The created() lifecycle callback method is called when a domain object has just been instantiated using FactoryService

An alternative means to interact with the lifecycle is by setting up a subscriber on the @DomainObject#createdLifecycleEvent() event.

This lifecycle method (or subscriber) is not called if the domain object using a regular constructor.

For this reason use of this callback or event is discouraged.

loaded()

The loaded() lifecycle callback method is called when a (persistent) object has just been loaded from the object store.

An alternative means to interact with the lifecycle is by setting up a subscriber on the @DomainObject#loadedLifecycleEvent() event.

persisting()

The persisting() lifecycle callback method is called when a (not-yet-persistent) object is just about to be persisted from the object store

An alternative means to interact with the lifecycle is by setting up a subscriber on the @DomainObject#persistingLifecycleEvent() event.

See also persisted() callback.

persisted()

The persisted() lifecycle callback method is called when object has just been persisted from the object store.

An alternative means to interact with the lifecycle is by setting up a subscriber on the @DomainObject#persistedLifecycleEvent() event.

See also the persisting() callback.

updating()

The updating() lifecycle callback method is called when a (persistent) object is just about to be updated in the object store

An alternative means to interact with the lifecycle is by setting up a subscriber on the @DomainObject#updatingLifecycleEvent() event.

See also updated().

updated()

The updated() lifecycle callback method is called when a (persistent) object has just been updated in the object store

An alternative means to interact with the lifecycle is by setting up a subscriber on the @DomainObject#updatedLifecycleEvent() event.

See also updating().

removing()

The removing() lifecycle callback method is called when a (persistent) object is just about to be deleted from the object store

An alternative means to interact with the lifecycle is by setting up a subscriber on the @DomainObject#removingLifecycleEvent() event.

Unlike the persisting() /persisted() andupdating() /updated() callbacks, there is no removed() callback. That’s because its not valid to interact with a persistent domain object once its been deleted.