in core/src/main/java/org/hibernate/ogm/persister/impl/OgmEntityPersister.java [1503:1581]
public void delete(Serializable id, Object version, Object object, SharedSessionContractImplementor session)
throws HibernateException {
final int span = getTableSpan();
if ( span > 1 ) {
throw new HibernateException( "Hibernate OGM does not yet support entities spanning multiple tables" );
}
final EntityKey key = EntityKeyBuilder.fromPersister( this, id, session );
Object[] loadedState = getLoadedState( id, session );
Tuple currentState = null;
if ( mightManageInverseAssociations || usesNonAtomicOptimisticLocking ) {
currentState = gridDialect.getTuple( key, getTupleContext( session ) );
}
if ( usesNonAtomicOptimisticLocking ) {
checkOptimisticLockingState( id, key, object, loadedState, version, session, currentState );
}
for ( int j = span - 1; j >= 0; j-- ) {
if ( isInverseTable( j ) ) {
return;
}
if ( log.isTraceEnabled() ) {
log.trace( "Deleting entity: " + MessageHelper.infoString( this, id, getFactory() ) );
if ( j == 0 && isVersioned() ) {
log.trace( "Version: " + version );
}
}
if ( gridDialect.usesNavigationalInformationForInverseSideOfAssociations() ) {
//delete inverse association information
//needs to be executed before the tuple removal because the AtomicMap in ISPN is cleared upon removal
if ( mightManageInverseAssociations ) {
new EntityAssociationUpdater( this )
.id( id )
.resultset( currentState )
.session( session )
.tableIndex( j )
.propertyMightRequireInverseAssociationManagement( propertyMightBeMainSideOfBidirectionalAssociation )
.removeNavigationalInformationFromInverseSide();
}
if ( mightHaveNavigationalInformation ) {
removeNavigationInformation( id, object, session );
}
}
if ( optimisticLockingAwareGridDialect != null && isVersioned() ) {
Tuple versionTuple = new Tuple();
versionTuple.put( getVersionColumnName(), version );
boolean success = optimisticLockingAwareGridDialect.removeTupleWithOptimisticLock( key, versionTuple, getTupleContext( session ) );
// If there is an error handler registered, pass the applied/failed operation to it as needed
if ( success ) {
if ( invocationCollectingGridDialect != null ) {
invocationCollectingGridDialect.onRemoveTupleWithOptimisticLockSuccess( key, versionTuple );
}
}
else {
if ( invocationCollectingGridDialect != null ) {
try {
raiseStaleObjectStateException( id );
}
catch (Exception e) {
invocationCollectingGridDialect.onRemoveTupleWithOptimisticLockFailure( key, versionTuple, e );
}
}
else {
raiseStaleObjectStateException( id );
}
}
}
else {
gridDialect.removeTuple( key, getTupleContext( session ) );
}
}
}