Class IdTransferringMergeEventListener

  extended by org.hibernate.event.def.AbstractEventListener
      extended by org.hibernate.event.def.AbstractReassociateEventListener
          extended by org.hibernate.event.def.AbstractSaveEventListener
              extended by org.hibernate.event.def.DefaultMergeEventListener
                  extended by
All Implemented Interfaces:
Serializable, MergeEventListener

public class IdTransferringMergeEventListener
extends DefaultMergeEventListener

Extension of Hibernate's DefaultMergeEventListener, transferring the ids of newly saved objects to the corresponding original objects (that are part of the detached object graph passed into the merge method).

Transferring newly assigned ids to the original graph allows for continuing to use the original object graph, despite merged copies being registered with the current Hibernate Session. This is particularly useful for web applications that might want to store an object graph and then render it in a web view, with links that include the id of certain (potentially newly saved) objects.

The merge behavior given by this MergeEventListener is nearly identical to TopLink's merge behavior. See PetClinic for an example, which relies on ids being available for newly saved objects: the HibernateClinic and TopLinkClinic DAO implementations both use straight merge calls, with the Hibernate SessionFactory configuration specifying an IdTransferringMergeEventListener.

Typically specified as entry for LocalSessionFactoryBean's "eventListeners" map, with key "merge".

NOTE: Due to incompatible changes in the Hibernate 3.1 event listener API (according to the Hibernate 3.1 RC1 release that was available at the time of this writing), this merge event listener will currently only work as-is with Hibernate 3.0. Consider copying this implementation and adapting it to the changed API if you want to run it against Hibernate 3.1.

Spring 2.0 is likely to update its default implementation of this class to Hibernate 3.1, even if the remainder of Spring 2.0's Hibernate3 support will stay compatible with Hibernate 3.0.

Juergen Hoeller
See Also:
LocalSessionFactoryBean.setEventListeners(java.util.Map), Serialized Form

Field Summary
Fields inherited from class org.hibernate.event.def.AbstractSaveEventListener
Constructor Summary
Method Summary
protected  Object entityIsTransient(MergeEvent event, Map copyCache)
          Hibernate 3.0 implementation of ID transferral.
Methods inherited from class org.hibernate.event.def.DefaultMergeEventListener
cascadeOnMerge, copyValues, entityIsDetached, entityIsPersistent, getAssumedUnsaved, getCascadeAction, onMerge, onMerge
Methods inherited from class org.hibernate.event.def.AbstractSaveEventListener
cascadeAfterSave, cascadeBeforeSave, getEntityState, isVersionIncrementDisabled, performSave, performSaveOrReplicate, saveWithGeneratedId, saveWithRequestedId, substituteValuesIfNecessary, visitCollectionsBeforeSave
Methods inherited from class org.hibernate.event.def.AbstractReassociateEventListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public IdTransferringMergeEventListener()
Method Detail


protected Object entityIsTransient(MergeEvent event,
                                   Map copyCache)
Hibernate 3.0 implementation of ID transferral. Comment this out and the below in for a Hibernate 3.1 version of this class.

entityIsTransient in class DefaultMergeEventListener

Copyright (c) 2002-2007 The Spring Framework Project.