接口 Lifecycle
-
public interface LifecycleProvides callbacks from the Session to the persistent object. Persistent classes may implement this interface but they are not required to.
onSave: called just before the object is saved
onUpdate: called just before an object is updated, ie. when Session.update() is called
onDelete: called just before an object is deleted
onLoad: called just after an object is loaded
onLoad() may be used to initialize transient properties of the object from its persistent state. It may not be used to load dependent objects since the Session interface may not be invoked from inside this method.
A further intended usage of onLoad(), onSave() and onUpdate() is to store a reference to the Session for later use.
If onSave(), onUpdate() or onDelete() return VETO, the operation is silently vetoed. If a CallbackException is thrown, the operation is vetoed and the exception is passed back to the application.
Note that onSave() is called after an identifier is assigned to the object, except when identity column key generation is used.- 作者:
- Gavin King
- 另请参阅:
CallbackException
-
-
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 booleanonDelete(Session s)Called when an entity is deleted.voidonLoad(Session s, Serializable id)Called after an entity is loaded.booleanonSave(Session s)Called when an entity is saved.booleanonUpdate(Session s)Called when an entity is passed to Session.update().
-
-
-
方法详细资料
-
onSave
boolean onSave(Session s) throws CallbackException
Called when an entity is saved.- 参数:
s- the session- 返回:
- true to veto save
- 抛出:
CallbackException- Indicates a problem happened during callback
-
onUpdate
boolean onUpdate(Session s) throws CallbackException
Called when an entity is passed to Session.update(). This method is not called every time the object's state is persisted during a flush.- 参数:
s- the session- 返回:
- true to veto update
- 抛出:
CallbackException- Indicates a problem happened during callback
-
onDelete
boolean onDelete(Session s) throws CallbackException
Called when an entity is deleted.- 参数:
s- the session- 返回:
- true to veto delete
- 抛出:
CallbackException- Indicates a problem happened during callback
-
onLoad
void onLoad(Session s, Serializable id)
Called after an entity is loaded. It is illegal to access the Session from inside this method. However, the object may keep a reference to the session for later use.- 参数:
s- the sessionid- the identifier
-
-