A lifecycle of a persistent object can be represented as a number of states and transitions between them. These states are formally defined as "int" constants in org.apache.cayenne.PersistenceState class. Transitions between states (see the diagram below) occur in response to the application interacting with either persistent objects or Cayenne context. Whenever a transition occurs, Cayenne automatically updates "persistenceState" property of all affected objects by calling setPersistenceState().
A new object state transformations: |
A fetched or committed object state transformations: |
The states are defined as follows:
State | Value | Description |
---|---|---|
TRANSIENT | 1 | The object is not registered in a DataContext and will not persist. |
NEW | 2 | The object is freshly registered in a DataContext, but has not been persisted to the database (there is no matching database record). |
COMMITTED | 3 | The object is registered in a DataContext and has been persisted to the database (there is a matching database record). |
MODIFIED | 4 | The object is registered in a DataContext and there is a matching database record and the object has been modified in memory, but the changes have not yet been persisted back to the database. |
HOLLOW | 5 | The object is registered in a DataContext and has a corresponding database row, but the values have not yet been fetched from the database. The values will be fetched/faulted from the database automatically by Cayenne if any fields are requested from the object. |
DELETED | 6 | The object is registered in a DataContext and will be deleted from the database upon commit. |