It looks like i was barking up the wrong tree!

After digging through the NH3.2 source, the logic I read looked just
like I had expected the behavior to be -- Equals can be overridden
*anywhere* in the hierarchy (up to System.Object).

Instead, the problem was in *my* Equals method where I guard against
the proxies with a crude but agnostic check if the namespace isn't one
of my own.  I was not considering that the proxied class' namespace
might be null.  Under Castle, it wasn't; however, NH3.2's built-in
proxies do use a null namespace.

I fixed my logic to accommodate null namespaces and it now appears to
be working.

On Oct 31, 2:58 pm, Trinition <[email protected]> wrote:
> I've just stumbled upon a bug in my app that I think is due to my
> misunderstanding of NHibernate.  I'm hoping the community can help me
> clarify.
>
> I have a BaseEntity class that provides some basic housekeeping
> functions, but most importantly provides some (hopefully) robust
> Equals and GetHashCode methods.  I have a slew of my own unit tests
> that verify the correctness reflexiveness of them.
>
> Upon these, I have some a hierarchy of business entities:
>
> class Product : BaseEntity
> class SpecialProduct : Product
>
> None of these classes override Equals (nor GetHashCode) but rely upon
> the implementations in BaseEntity.  Meanwhile, I have another class,
> ProductSettings, that has an IDictionary<Product,Settings>.
>
> If SpecialProduct is retrieved from my repository, it does *not* match
> itself as the key in the dictionary.  At runtime, the key is a
> ProductProxy and the retrieved entity is a SpecialProduct.  Debugging,
> I've found that it's not reflexive:
>
>     myProductProxy.Equals(mySpecialProduct) // false
>     mySpecialProduct.Equals(myProductProxy) // true
>
> Googling, I found the following thread which suggests that NH3.2's
> proxies only check the base class (i.e. Product) for Equals/
> GetHashCode implementations, but higher up (i.e. BaseEntity):
>
>    http://groups.google.com/group/nhibernate-development/msg/fb6e323875e...
>
> To test this theory, I went to Product and implemented Equals() and
> GetHashCode() to both delegate to their base.  Now the objects are
> reflexively equal:
>
>     myProductProxy.Equals(mySpecialProduct) // true
>     mySpecialProduct.Equals(myProductProxy) // false
>
> Now I don't know if I'm expecting the wrong behavior out of NHibernate
> and its proxies (i.e. that it should leverage my Equals no matter
> where it comes from in the hierarchy), or if I've had the dumb luck to
> stumble upon a bug (I think the liklihood of me encountering this
> before anyone else is small).
>
> Do any of you fellow NHibernate 3.2 users have thoughts one way or the
> other?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
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