2013/11/20 Roger Kratz <[email protected]> > Yes, forgot to mention… In this case the key instance is the very same > instance, just modify its data so no changes that affects Equals or > GetHashcode. > >
Not sure I understand - are you saying that this exception and duplication occurs also when the key is modified only in such a way that it's hashcode and equals methods are _not_ affected? I assume that the exception you get is a KeyNotFoundException - and this will occur if the hash code has changed, because the dictionary will no longer be able to locate the collection member. For NH3, the non-generic EqualsSnapshot() from PersistentMap is used, based on the non-generic IDictionary interface. The indexer from that interface simply returns null instead of KeyNotFoundException, which the following call to IsDirty() apparently handles without exception. Anyway, the pull request does harden the code in the face of contract violations (but see Patrick's suggestions) - but we should realize that there is no defined behavior for what should happen when the hashcode of an object used as dictionary key is modified. So basically anything can happen and no-one can complain about it. As for the duplication, I would guess that there is some other place in PersistentGenericMap where keys are looked up in a similar way, where some code might decide that this is a new entry. /Oskar > > I just pushed my proposal of fix to the old pull request > > https://github.com/nhibernate/nhibernate-core/pull/229 > > > > If you don’t agree I can fix Envers tests (there’s lot of old ported Java > tests currently failing) instead, but I’ll be happy to get some input first. > > > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Oskar Berggren > *Sent:* den 20 november 2013 13:39 > *To:* [email protected] > *Subject:* Re: [nhibernate-development] NH-3555 > > > > Changing something that affects Equals()/GetHashCode() of an object while > that object is the key of a dictionary isn't allowed by the IDictionary > contract. What behavior should we expect? > > /Oskar > > > > 2013/11/20 Roger Kratz <[email protected]> > > Hi > > > > I reported regression bug 3555 some time ago. This issue currently > prevents releasing an Envers version targeting NH 4. > > > > I’m sitting trying to fixing the issue myself, but run into an issue > whether old behavior is correct or not. > > > > What the issue is all about is… > > > > var key = new KeyEntity(); > > var value = new ValueEntity(); > > var entity = new MapEntity(); > > entity.SomeMapProp[key] = value; (1) > > > > [open session] > > [begin tran] > > [save entity] > > [commit tran] > > [begin tran] > > Key.SomeProperty = newvalue; (2) > > [commit tran] > > [/close session] > > > > ….in other words; changing the key object of an entry in a map/dictionary. > > > > In current NH 4 code base, code above throws. I’ve fixed the problem > locally but noticed that my “fix” got another result than NH 3. In NH 3 > code above resulted in _*two*_ entries in the map – both (1) and (2), > while my local fix resulted in one entry (only 2). I personally think the > behavior in NH 3 was wrong. > > > > I’ll be glad to fix this issue so a new Envers version could be released > together with NH 4 alpha 2 but I need to double check with you first what > the “correct” behavior is in this case. Any opinions? > > > > All the best, > > Roger > > > > > > > > -- > > --- > You received this message because you are subscribed to the Google Groups > "nhibernate-development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > > -- > > --- > You received this message because you are subscribed to the Google Groups > "nhibernate-development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > -- > > --- > You received this message because you are subscribed to the Google Groups > "nhibernate-development" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- --- You received this message because you are subscribed to the Google Groups "nhibernate-development" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
