= Lifecycle Methods

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.



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:

.Lifecycle methods (partial support)
[cols="1m,3a,2m", options="header"]
|===

|Method
|Description
|Event +
equivalent

|created()
|called when an object has just been created using xref:refguide:applib:index/services/factory/FactoryService.adoc[FactoryService#create(..)] or xref:refguide:applib:index/services/repository/RepositoryService.adoc[RepositoryService#detachedEntity(...)]
|xref:refguide:applib:index/events/lifecycle/ObjectCreatedEvent.adoc[ObjectCreatedEvent]

|loaded()
|called when a (persistent) object has just been loaded from the object store.
|xref:refguide:applib:index/events/lifecycle/ObjectLoadedEvent.adoc[ObjectLoadedEvent]

|persisted()
|called when object has just been persisted from the object store.
|xref:refguide:applib:index/events/lifecycle/ObjectPersistedEvent.adoc[ObjectPersistedEvent]

|persisting()
|called when a (not-yet-persistent) object is just about to be persisted from the object store
|xref:refguide:applib:index/events/lifecycle/ObjectPersistingEvent.adoc[ObjectPersistingEvent]

|removing()
|called when a (persistent) object is just about to be deleted from the object store
|xref:refguide:applib:index/events/lifecycle/ObjectRemovingEvent.adoc[ObjectRemovingEvent]

|updated()
|called when a (persistent) object has just been updated in the object store
|xref:refguide:applib:index/events/lifecycle/ObjectUpdatedEvent.adoc[ObjectUpdatedEvent]

|updating()
|called when a (persistent) object is just about to be updated in the object store
|xref:refguide:applib:index/events/lifecycle/ObjectUpdatingEvent.adoc[ObjectUpdatingEvent]

|===

Further discussion on using events and a subscriber (which will result in a more flexible/decoupled design) can be found xref:applib-classes:events.adoc#lifecycle-events[here].

include::partial$lifecycle/created.adoc[leveloffset=+1]
include::partial$lifecycle/loaded.adoc[leveloffset=+1]
include::partial$lifecycle/persisting.adoc[leveloffset=+1]
include::partial$lifecycle/persisted.adoc[leveloffset=+1]
include::partial$lifecycle/updating.adoc[leveloffset=+1]
include::partial$lifecycle/updated.adoc[leveloffset=+1]
include::partial$lifecycle/removing.adoc[leveloffset=+1]
