views:

81

answers:

0

i am in the middle of re factoring an application and i've applied an interface on most entities. I want to change the Save/Update behavior of these entities using the Event mechanism of NH2.1.1. As such i'm implementing an NHibernate.Event.ISaveOrUpdateEventListener

public class SaveOrUpdate : ISaveOrUpdateEventListener
{
    public void OnSaveOrUpdate(SaveOrUpdateEvent @event)
    {
        if (@event.Entity is IFoobar)
        {
                ...
        }
    }
}

the thing is that the application is already using cascade="save-update" and cascade="all" and in most occasions i have a Parent/Child relationship that both entities implement IFoobar. Up until now the collections where updated/saved by NH but now this will change and so i ask: Do i need to implement any other NHibernate.Event interfaces to accomondate for this need or will this suffice and for each collection entity this custom listener is called?

EDIT: Moreover, this operation involves not running the default Update/Delete operations; the Entities will be marked mutable="false" and they also will contain a <version /> element. The only thing that will remain the same is the Save() which is a normal insert and all other operations will be handled with additional inserts.

I want to avoid application-wide re factoring so i will need to implement my own listeners so all if any changes will occur in the additional listeners and/or in the AbstractDAO i already implement. In the reference (11.2) it states that we register the custom listener but also registers the default listener. If i don't register the Default listener via configuration will it also fire? If so how do i handle that since there will be some entities that will maintain default nhibernate behavior?

Any tips are appreciated, unfortunately listeners and their implementation are scarcely documented and examples are rare