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, this merge event listener will only work as-is with Hibernate 3.1+. Consider
copying this implementation and adapting it to the older API if you want to run
it against Hibernate 3.0.
author: Juergen Hoeller since: 1.2 See Also: org.springframework.orm.hibernate3.LocalSessionFactoryBean.setEventListeners(java.util.Map) |