in core/src/main/java/org/hibernate/ogm/persister/impl/OgmCollectionPersister.java [498:540]
public void deleteRows(PersistentCollection collection, Serializable id, SharedSessionContractImplementor session)
throws HibernateException {
if ( !isInverse && isRowDeleteEnabled() ) {
if ( log.isDebugEnabled() ) {
log.debug( "Deleting rows of collection: " + MessageHelper.collectionInfoString( this, id, getFactory() ) );
}
boolean deleteByIndex = !isOneToMany() && hasIndex && !indexContainsFormula;
AssociationPersister associationPersister = getAssociationPersister( collection.getOwner(), id, session );
// delete all the deleted entries
Iterator<?> deletes = collection.getDeletes( this, !deleteByIndex );
if ( deletes.hasNext() ) {
int count = 0;
while ( deletes.hasNext() ) {
Object entry = deletes.next();
// find the matching element
RowKey assocEntryKey = getTupleKeyForDelete( id, collection, session, entry, deleteByIndex, associationPersister );
Tuple assocEntryTuple = associationPersister.getAssociation().get( assocEntryKey );
if ( assocEntryTuple == null ) {
throw new AssertionFailure( "Deleting a collection tuple that is not present: " + "table {" + getTableName() + "} collectionKey {" + id + "} entry {" + entry + "}" );
}
// delete the tuple
updateInverseSideOfAssociationNavigation( session, entry, associationPersister.getAssociationKey(), assocEntryTuple, Action.REMOVE, assocEntryKey );
associationPersister.getAssociation().remove( assocEntryKey );
count++;
}
associationPersister.flushToDatastore();
if ( log.isDebugEnabled() ) {
log.debug( "done deleting collection rows: " + count + " deleted" );
}
}
else {
log.debug( "no rows to delete" );
}
}
}