Java Reference
In-Depth Information
By obtaining a JDBC connection from the session, it is of course possible to invoke stored
procedures directly; however, you must be aware that the Hibernate session cache cannot
track these updates.
Events
Hibernate 3 actually implements most of its functionality as event listeners. When you regis-
ter a listener with Hibernate, the listener entirely supplants the default functionality. For
example, the EJB 3-specific behavior required when using an EntityManager is achieved by
plugging in a set of EJB 3-specific event listeners!
If you look at the methods of the SessionImpl class, which is the internal Hibernate
implementation of the Session interface, you'll see why this is the case. Most of the meth-
ods have a form very similar to that shown in Listing A-21.
Listing A-21. The Implementation of a Typical Method in SessionImpl
SaveOrUpdateEvent event = new SaveOrUpdateEvent(entityName, obj, this);
listeners.getSaveOrUpdateEventListener().onSaveOrUpdate(event);
The listeners field is an instance of SessionEventListenerConfig , which provides the
requested event listener, or the default if none is specified. So, if your event listener is provided
and doesn't call the default one, nothing else can.
Event listeners are always registered globally for the event that they handle. You can regis-
ter them in the configuration file or programmatically. Either way, you will need to map your
implementation of one of the interfaces to the associated types, which you can look up in
Table A-1. (The names are almost—but not quite—standardized.)
Table A-1. The Listener Names and Their Corresponding Interfaces
Type Name
Listener
auto-flush
AutoFlushEventListener
delete
DeleteEventListener
dirty-check
DirtyCheckEventListener
evict
EvictEventListener
flush
FlushEventListener
flush-entity
FlushEntityEventListener
load
LoadEventListener
load-collection
InitializeCollectionEventListener
lock
LockEventListener
merge
MergeEventListener
persist
PersistEventListener
post-delete
PostDeleteEventListener
post-insert
PostInsertEventListener
post-load
PostLoadEventListener
post-update
PostUpdateEventListener
Search WWH ::




Custom Search