FileDocCategorySizeDatePackage
Interceptor.javaAPI DocHibernate 3.2.57001Fri Aug 12 15:03:08 BST 2005org.hibernate

Interceptor

public interface Interceptor
Allows user code to inspect and/or change property values.

Inspection occurs before property values are written and after they are read from the database.

There might be a single instance of Interceptor for a SessionFactory, or a new instance might be specified for each Session. Whichever approach is used, the interceptor must be serializable if the Session is to be serializable. This means that SessionFactory-scoped interceptors should implement readResolve().

The Session may not be invoked from a callback (nor may a callback cause a collection or proxy to be lazily initialized).

Instead of implementing this interface directly, it is usually better to extend EmptyInterceptor and override only the callback methods of interest.
see
SessionFactory#openSession(Interceptor)
see
org.hibernate.cfg.Configuration#setInterceptor(Interceptor)
see
EmptyInterceptor
author
Gavin King

Fields Summary
Constructors Summary
Methods Summary
public voidafterTransactionBegin(Transaction tx)
Called when a Hibernate transaction is begun via the Hibernate Transaction API. Will not be called if transactions are being controlled via some other mechanism (CMT, for example).

public voidafterTransactionCompletion(Transaction tx)
Called after a transaction is committed or rolled back.

public voidbeforeTransactionCompletion(Transaction tx)
Called before a transaction is committed (but not before rollback).

public int[]findDirty(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] currentState, java.lang.Object[] previousState, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
Called from flush(). The return value determines whether the entity is updated
  • an array of property indices - the entity is dirty
  • an empty array - the entity is not dirty
  • null - use Hibernate's default dirty-checking algorithm

param
entity a persistent entity
return
array of dirty property indices or null to choose default behaviour

public java.lang.ObjectgetEntity(java.lang.String entityName, java.io.Serializable id)
Get a fully loaded entity instance that is cached externally

param
entityName the name of the entity
param
id the instance identifier
return
a fully initialized entity
throws
CallbackException

public java.lang.StringgetEntityName(java.lang.Object object)
Get the entity name for a persistent or transient instance

param
object an entity instance
return
the name of the entity

public java.lang.Objectinstantiate(java.lang.String entityName, EntityMode entityMode, java.io.Serializable id)
Instantiate the entity class. Return null to indicate that Hibernate should use the default constructor of the class. The identifier property of the returned instance should be initialized with the given identifier.

param
entityName the name of the entity
param
entityMode The type of entity instance to be returned.
param
id the identifier of the new instance
return
an instance of the class, or null to choose default behaviour

public java.lang.BooleanisTransient(java.lang.Object entity)
Called to distinguish between transient and detached entities. The return value determines the state of the entity with respect to the current session.
  • Boolean.TRUE - the entity is transient
  • Boolean.FALSE - the entity is detached
  • null - Hibernate uses the unsaved-value mapping and other heuristics to determine if the object is unsaved

param
entity a transient or detached entity
return
Boolean or null to choose default behaviour

public voidonCollectionRecreate(java.lang.Object collection, java.io.Serializable key)
Called before a collection is (re)created.

public voidonCollectionRemove(java.lang.Object collection, java.io.Serializable key)
Called before a collection is deleted.

public voidonCollectionUpdate(java.lang.Object collection, java.io.Serializable key)
Called before a collection is updated.

public voidonDelete(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
Called before an object is deleted. It is not recommended that the interceptor modify the state.

public booleanonFlushDirty(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] currentState, java.lang.Object[] previousState, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
Called when an object is detected to be dirty, during a flush. The interceptor may modify the detected currentState, which will be propagated to both the database and the persistent object. Note that not all flushes end in actual synchronization with the database, in which case the new currentState will be propagated to the object, but not necessarily (immediately) to the database. It is strongly recommended that the interceptor not modify the previousState.

return
true if the user modified the currentState in any way.

public booleanonLoad(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
Called just before an object is initialized. The interceptor may change the state, which will be propagated to the persistent object. Note that when this method is called, entity will be an empty uninitialized instance of the class.

return
true if the user modified the state in any way.

public java.lang.StringonPrepareStatement(java.lang.String sql)
Called when sql string is being prepared.

param
sql sql to be prepared
return
original or modified sql

public booleanonSave(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
Called before an object is saved. The interceptor may modify the state, which will be used for the SQL INSERT and propagated to the persistent object.

return
true if the user modified the state in any way.

public voidpostFlush(java.util.Iterator entities)
Called after a flush that actually ends in execution of the SQL statements required to synchronize in-memory state with the database.

public voidpreFlush(java.util.Iterator entities)
Called before a flush