Hi all,

I have a user that has a number of roles. The user is linked to the roles 
using a link entity table. I have set the configuration 

file to cascade delete the user role link entities when a user is deleted.


We are currently using soft delete to delete entities. We have added a soft 
delete event listener that is triggered by a delete. 

When an entity is being deleted, it triggers the DeleteEntity event which 
marks the entity as deleted.

 

We also have an override the OnPostUpdate event to remove the entities from 
the cache by calling Evict on the entity (so the deleted entity is cleared 
from the cache).

 

If I create a user without any roles and then delete it, everything works 
fine. However if I have a user with at least one role assigned and I 

delete the user, after the call to Evict in OnPostUpdate, I get a 
Nhibernate exception "*NHibernate.AssertionFailure: Possible nonthreadsafe 
access to session*"

 

I have tried, in OnPostUpdate, to use the child session to Evict the 
entity. In that case the exception is not thrown, however, the entity is 
not evicted.

 

public void UserDelete(.....)

{

                 var user = repository.Fetch<User>(id);

                 repository.Remove(user);

                repository.Connection.Commit();

}

 

 // soft delete event listener

protected override void DeleteEntity(NHibernate.Event.IEventSource session, 
object entity, ..)

{              

                var repositoryEntity = entity as deletableentity;

                 if (repositoryEntity != null)

                {

                                if (!repositoryEntity.IsDeleted)

                                {

                                                // this marks the entity as 
deleted

                                                repositoryEntity.isDeleted 
= true;

                                                 // cascade delete

                                                
this.CascadeBeforeDelete(session, persister, repositoryEntity, entityEntry, 
transientEntities);

                                                
this.CascadeAfterDelete(session, persister, repositoryEntity, 
transientEntities);              

                                }

                }

}

 

public void OnPostUpdate(PostUpdateEvent @event)

{

                if (@event == null) throw new 
ArgumentNullException("event");

                 var entity = @event.Entity as deletableentity;

                 // Evict any entities that have been set as deleted from 
first level cache.

                if (entity != null && entity.IsDeleted)

                {

                                @event.Session.Evict(entity);

                }

}

Any ideas?


Thank you,

Aleksej

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/7s72cACvUbwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to