Package org.hibernate.classic
Interface Lifecycle
-
public interface LifecycleProvides callbacks from theSessionto 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 theSessioninterface may not be invoked from inside this method.A further intended usage of
onLoad(),onSave()andonUpdate()is to store a reference to theSessionfor later use.If
onSave(),onUpdate()oronDelete()returnVETO, the operation is silently vetoed. If aCallbackExceptionis 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.- See Also:
CallbackException,EntityListeners,PrePersist,PreRemove,PreUpdate,PostLoad,PostPersist,PostRemove,PostUpdate
-
-
Method Summary
All Methods Instance Methods Default Methods Deprecated Methods Modifier and Type Method Description default booleanonDelete(Session s)Called when an entity is deleted.default voidonLoad(Session s, Serializable id)Deprecated.default voidonLoad(Session s, Object id)Called after an entity is loaded.default booleanonSave(Session s)Called when an entity is saved.default booleanonUpdate(Session s)Called when an entity is passed toSession.update().
-
-
-
Field Detail
-
VETO
static final boolean VETO
Return value to veto the action (true)- See Also:
- Constant Field Values
-
NO_VETO
static final boolean NO_VETO
Return value to accept the action (false)- See Also:
- Constant Field Values
-
-
Method Detail
-
onSave
default boolean onSave(Session s) throws CallbackException
Called when an entity is saved.- Parameters:
s- the session- Returns:
- true to veto save
- Throws:
CallbackException- Indicates a problem happened during callback
-
onUpdate
default boolean onUpdate(Session s) throws CallbackException
Called when an entity is passed toSession.update(). This method is not called every time the object's state is persisted during a flush.- Parameters:
s- the session- Returns:
- true to veto update
- Throws:
CallbackException- Indicates a problem happened during callback
-
onDelete
default boolean onDelete(Session s) throws CallbackException
Called when an entity is deleted.- Parameters:
s- the session- Returns:
- true to veto delete
- Throws:
CallbackException- Indicates a problem happened during callback
-
onLoad
default void onLoad(Session s, Object id)
Called after an entity is loaded. It is illegal to access theSessionfrom inside this method. However, the object may keep a reference to the session for later use.- Parameters:
s- the sessionid- the identifier
-
onLoad
@Deprecated(since="6.0") default void onLoad(Session s, Serializable id)
Deprecated.Called after an entity is loaded. It is illegal to access theSessionfrom inside this method. However, the object may keep a reference to the session for later use.- Parameters:
s- the sessionid- the identifier
-
-