8.2. Lifecycle Listeners

Naked Objects provides a number of well-defined callbacks into the domain object lifecycle. These are implemented as facets that search for well-defined methods:

These callbacks are supported by all object store implementations. A typical example is to capture the ID for use within a domain object.

In addition, the JPA specification defines a number of annotations that also define callbacks into the persistence lifecycle. Because these are implemented by the JPA provider (Hibernate), they won't be portable across different object stores. However, they may well be of use in production code.

The callbacks provided are (methods annotated using):

For more on these callbacks, see for example this article from Oracle's technical documentation.

Alternatively, the @EntityListeners annotation can be used to specify another class to be notified.