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.  [ 4 posts ] 
Author Message
 Post subject: Interceptors, OnFlushDirty & the Trunk
PostPosted: Mon Oct 29, 2007 1:44 pm 
Beginner
Beginner

Joined: Wed Oct 04, 2006 8:57 am
Posts: 25
I am using the trunk version of NHibernate and have noticed some
changes since I last updated (about a month or two ago I think).

(I think) OnFlushDirty used to only receive the primititive types of an
object that had changed. It now seems to be receiving all properties
including mapped clases and persistent collections.

Is this supposed to be happening?
It is causing my auditing interceptor to have trouble.. I need to only
track changes to the primitive types not any references objects. Is
there a good way to figure out what those values are?

Thanks.


Top
 Profile  
 
 Post subject: Re: Interceptors, OnFlushDirty & the Trunk
PostPosted: Fri Nov 02, 2007 12:22 pm 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
derek.ekins wrote:
I need to only
track changes to the primitive types not any references objects. Is
there a good way to figure out what those values are?

Thanks.


Since you have the objects you could always just get the object's type and check to see if it is a primitive using the below code:


Code:
obj.GetType().IsPrimitive


If you want more information see:
http://msdn2.microsoft.com/en-us/library/system.type.isprimitive.aspx


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 02, 2007 2:19 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
It's not that straightforward. DateTime isn't considerered primitive, for example. And what about stuff like byte arrays, nullable ints and bools, etc?

Fortunately for us, our entities implement a specific interface, so we already have code (in other places) to determine if an entity property is "simple" by checking if it implements our entity interface or IList. If it implements neither, it's a "simple" type.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 05, 2007 8:22 am 
Beginner
Beginner

Joined: Wed Oct 04, 2006 8:57 am
Posts: 25
Thanks for the replies.
I ended up doing this:

Code:
                    List<object> previous = new List<object>();
                    List<object> current = new List<object>();
                    List<string> properties = new List<string>();

                    // need to make strip out all the persistent objects
                    using (ISession session = this.sessionManager.OpenSession())
                    {
                        for (int index = 0; index < changes.Previous.Length; index++)
                        {
                            if (!session.Contains(changes.Previous[index]) && !session.Contains(changes.Current[index]) &&
                                !(changes.Previous[index] is IPersistentCollection) &&
                                !(changes.Current[index] is IPersistentCollection))
                            {
                                previous.Add(changes.Previous[index]);
                                current.Add(changes.Current[index]);
                                properties.Add(changes.Properties[index]);
                            }
                        }
                    }


Just checking to see if the object is in session. If it is then I just ignore it. Also ignore any objects that implement IPersistentCollection.

I imagine this will start breaking if I evict objects from session. Maybe it would be better to get the type of each object and check it against the mappings?


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

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.