持久化对象的生存期可以描述为可以相互转化的几种状态,并且预定义了整数型的常量值,定义在org.apache.cayenne.PersistenceState 类中。在应用程序和持久化对象或者Cayenne上下文交互时,状态发生变化。无论什么时候状态发生了变化,Cayenne会调用setPersistenceState()方法,自动更新所有受到影响的对象的persistenceState的属性值。
新建对象的状态变化: | 自动获取或者提交对象状态变化: |
预定义的几种状态:
状态 | 值 | 描述 |
---|---|---|
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. |
原文:
http://cayenne.apache.org/doc30/persistent-object-lifecycle.html