All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.classic.Lifecycle Maven / Gradle / Ivy

There is a newer version: 6.5.0.CR2
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.classic;
import java.io.Serializable;

import org.hibernate.CallbackException;
import org.hibernate.Session;

/**
 * Provides callbacks from the Session to the persistent object.
 * Persistent classes may implement this interface but they are not
 * required to.
*
* onSave: called just beforeQuery the object is saved
* onUpdate: called just beforeQuery an object is updated, * ie. when Session.update() is called
* onDelete: called just beforeQuery an object is deleted
* onLoad: called just afterQuery 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 afterQuery an identifier is assigned * to the object, except when identity column key generation is used. * * @see CallbackException * @author Gavin King */ public interface Lifecycle { /** * Return value to veto the action (true) */ public static final boolean VETO = true; /** * Return value to accept the action (false) */ public static final boolean NO_VETO = false; /** * Called when an entity is saved. * @param s the session * @return true to veto save * @throws CallbackException Indicates a problem happened during callback */ public boolean onSave(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. * @param s the session * @return true to veto update * @throws CallbackException Indicates a problem happened during callback */ public boolean onUpdate(Session s) throws CallbackException; /** * Called when an entity is deleted. * @param s the session * @return true to veto delete * @throws CallbackException Indicates a problem happened during callback */ public boolean onDelete(Session s) throws CallbackException; /** * Called afterQuery 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. * * @param s the session * @param id the identifier */ public void onLoad(Session s, Serializable id); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy