-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem Auditing a Collection
PostPosted: Wed Sep 16, 2009 4:53 pm 
Newbie

Joined: Thu Sep 03, 2009 7:27 pm
Posts: 2
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.-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.