public void execute() throws HibernateException { Serializable id = getId(); EntityPersister persister = getPersister(); SessionImplementor session = getSession(); Object instance = getInstance(); boolean veto = preDelete(); Object version = this.version; if (persister.isVersionPropertyGenerated()) { // we need to grab the version value from the entity, otherwise // we have issues with generated-version entities that may have // multiple actions queued during the same flush version = persister.getVersion(instance, session.getEntityMode()); } final CacheKey ck; if (persister.hasCache()) { ck = new CacheKey( id, persister.getIdentifierType(), persister.getRootEntityName(), session.getEntityMode(), session.getFactory()); lock = persister.getCacheAccessStrategy().lockItem(ck, version); } else { ck = null; } if (!isCascadeDeleteEnabled && !veto) { persister.delete(id, version, instance, session); } // postDelete: // After actually deleting a row, record the fact that the instance no longer // exists on the database (needed for identity-column key generation), and // remove it from the session cache final PersistenceContext persistenceContext = session.getPersistenceContext(); EntityEntry entry = persistenceContext.removeEntry(instance); if (entry == null) { throw new AssertionFailure("possible nonthreadsafe access to session"); } entry.postDelete(); persistenceContext.removeEntity(entry.getEntityKey()); persistenceContext.removeProxy(entry.getEntityKey()); if (persister.hasCache()) { persister.getCacheAccessStrategy().remove(ck); } postDelete(); if (getSession().getFactory().getStatistics().isStatisticsEnabled() && !veto) { getSession() .getFactory() .getStatisticsImplementor() .deleteEntity(getPersister().getEntityName()); } }