alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (Lifecycle.java)

This example Hibernate source code file (Lifecycle.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

callbackexception, callbackexception, io, lifecycle, lifecycle, no_veto, serializable, serializable, veto, veto

The Hibernate Lifecycle.java source code

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat Middleware LLC.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 *
 */
package org.hibernate.classic;
import java.io.Serializable;
import org.hibernate.CallbackException;
import org.hibernate.Session;

/**
 * Provides callbacks from the <tt>Session to the persistent object.
 * Persistent classes <b>may implement this interface but they are not
 * required to.<br>
 * <br>
 * <b>onSave: called just before the object is saved
* <b>onUpdate: called just before an object is updated, * ie. when <tt>Session.update() is called
* <b>onDelete: called just before an object is deleted
* <b>onLoad: called just after an object is loaded
* <br> * <tt>onLoad() may be used to initialize transient properties of the * object from its persistent state. It may <b>not be used to load * dependent objects since the <tt>Session interface may not be * invoked from inside this method.<br> * <br> * A further intended usage of <tt>onLoad(), onSave() and * <tt>onUpdate() is to store a reference to the Session * for later use.<br> * <br> * If <tt>onSave(), onUpdate() or onDelete() return * <tt>VETO, the operation is silently vetoed. If a * <tt>CallbackException is thrown, the operation is vetoed and the * exception is passed back to the application.<br> * <br> * Note that <tt>onSave() is called after 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 */ public boolean onSave(Session s) throws CallbackException; /** * Called when an entity is passed to <tt>Session.update(). * This method is <em>not called every time the object's * state is persisted during a flush. * @param s the session * @return true to veto update * @throws CallbackException */ public boolean onUpdate(Session s) throws CallbackException; /** * Called when an entity is deleted. * @param s the session * @return true to veto delete * @throws CallbackException */ public boolean onDelete(Session s) throws CallbackException; /** * Called after an entity is loaded. <em>It is illegal to * access the <tt>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); }

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate Lifecycle.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.