Hi,
I am not that new with Nhibernate, but i really haven't needed to use it in depth. So my problem might be very simple to solve, but right now i can't see well how.
I have 2 Classes, the Class A has a list "many-to-many" of the B. And B has the inverse list.
Having an object A1 and object B1 already existing, when I add B1 to the list in A1, the relation is persisted perfectly in the many to many table. Actually all works fine.
Now i needed to audit this change. So i created an interceptor that inherits of EmptyInterceptor.
I overrided the methods "OnFlushDirty" and "OnSave".
The problem i am having is that, when i add the object B1 to the list in A1 neither the method "OnFlushDirty" or "OnSave" of my interceptor are being called.
The interceptor works fine for other kind of changes, like changing a string property of an object type "A".
I have been researching a lot, but i couldn't find any place that mentioned that you can't intercept this kind of change, maybe is just i am looking in the wrong places.
So far what i did just for testing is override the method "FindDirty" in the interceptor, and when it intercepted the object where i was adding the collection i returned an array with ids. This produced the method "OnFlushDirty" to be called.
I am not sure what ids i should return in this method. Besides i am not convinced this is the correct way to acomplish what i want.
I have my objects like this: (I have changed the original names to make it more simple)
Code:
/*My class A*/
public class A
{
/*Other properties*/
private IList<B> listOfB;
public virtual IList<B> ListOfB
{
get
{
if (listOfB== null)
listOfB= new List<B>();
return listOfB;
}
protected set { listOfB= value; }
}
/*Other properties*/
}
/*Map of A (I am using Fluent)*/
/*Actually A is a subclass and is mapped with a discriminator, but i dont think that is my problem, so i simplified the mapping.*/
public class MapOfA:
{
/*Other Properties*/
HasManyToMany(x => x.ListOfB).Cascade.SaveUpdate().AsBag();
}
public class B
{
/*Other properties*/
private IList<A> listOfA;
public virtual IList<A> listOfA
{
get
{
if (listOfA== null)
listOfA= new List<A>();
return listOfA;
}
protected set { listOfA= value; }
}
}
/*Map of B*/
mapping.*/
public class MapOfA:
{
/*Other Properties*/
HasManyToMany(x => x.ListOfA).AsBag().Inverse();
}
I will appreciate any thoughts on this. I Hope i was clear enough, if not i will try to make clear any dark point.
Thank you for reading.-