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/fb6e323875ef4141
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.