final EventSource source = event.getSession();
final PersistenceContext persistenceContext = source.getPersistenceContext();
if ( object instanceof HibernateProxy ) {
final LazyInitializer li = ( (HibernateProxy) object ).getHibernateLazyInitializer();
final Serializable id = li.getIdentifier();
if ( id == null ) {
throw new IllegalArgumentException( "Could not determine identifier of proxy passed to evict()" );
}
final EntityPersister persister = source.getFactory().getEntityPersister( li.getEntityName() );
final EntityKey key = source.generateEntityKey( id, persister );
persistenceContext.removeProxy( key );
if ( !li.isUninitialized() ) {
final Object entity = persistenceContext.removeEntity( key );
if ( entity != null ) {
EntityEntry e = persistenceContext.removeEntry( entity );
doEvict( entity, key, e.getPersister(), event.getSession() );
}
}
li.unsetSession();
}
else {
EntityEntry e = persistenceContext.removeEntry( object );
if ( e != null ) {
persistenceContext.removeEntity( e.getEntityKey() );