DefaultEvictEventListenerpublic class DefaultEvictEventListener extends Object implements org.hibernate.event.EvictEventListenerDefines the default evict event listener used by hibernate for evicting entities
in response to generated flush events. In particular, this implementation will
remove any hard references to the entity that are held by the infrastructure
(references held by application or other persistent instances are okay) |
Fields Summary |
---|
private static final Log | log |
Methods Summary |
---|
protected void | doEvict(java.lang.Object object, org.hibernate.engine.EntityKey key, org.hibernate.persister.entity.EntityPersister persister, org.hibernate.event.EventSource session)
if ( log.isTraceEnabled() ) {
log.trace( "evicting " + MessageHelper.infoString(persister) );
}
// remove all collections for the entity from the session-level cache
if ( persister.hasCollections() ) {
new EvictVisitor( session ).process( object, persister );
}
new Cascade( CascadingAction.EVICT, Cascade.AFTER_EVICT, session )
.cascade( persister, object );
| public void | onEvict(org.hibernate.event.EvictEvent event)Handle the given evict event.
EventSource source = event.getSession();
final Object object = event.getObject();
final PersistenceContext persistenceContext = source.getPersistenceContext();
if ( object instanceof HibernateProxy ) {
LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
Serializable id = li.getIdentifier();
EntityPersister persister = source.getFactory().getEntityPersister( li.getEntityName() );
if ( id == null ) {
throw new IllegalArgumentException("null identifier");
}
EntityKey key = new EntityKey( id, persister, source.getEntityMode() );
persistenceContext.removeProxy( key );
if ( !li.isUninitialized() ) {
final Object entity = persistenceContext.removeEntity(key);
if ( entity != null ) {
EntityEntry e = event.getSession().getPersistenceContext().removeEntry(entity);
doEvict( entity, key, e.getPersister(), event.getSession() );
}
}
li.setSession( null );
}
else {
EntityEntry e = persistenceContext.removeEntry( object );
if ( e != null ) {
EntityKey key = new EntityKey( e.getId(), e.getPersister(), source.getEntityMode() );
persistenceContext.removeEntity( key );
doEvict( object, key, e.getPersister(), source );
}
}
|
|