NHibernate - Wrong Columns on Queries

后端 未结 1 2014
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 17:14

I\'m getting an intermittant problem with NHibernate where it generates a query for an entity, but replaces one of the columns with a column from completely different (and unrel

1条回答
  •  鱼传尺愫
    2021-02-05 17:53

    I asked the same question on the NHibernate Users Google Groups forum, and someone thinks they have worked out the root cause (and have also proposed a solution):

    https://groups.google.com/forum/#!topic/nhusers/BZoBoyWQEvs

    The problem code is in PropertyPath.Equals(PropertyPath) which attempts to determine equality by only using the hash code. This works fine for smaller code bases as the default Object.GetHashCode() returns a sequential object index. However, after garbage collection, these indices get reused as finalized objects are removed and new objects are created...which results in more than one object getting the same hashcode...Once garbage collection kicks in, property paths have a chance to share the same hashcode which means they will ultimately mix up their customizers for the colliding properties, thus the wrong column names...

    If you want to fix this the bug, you can patch the NH source code:

    If you have your own copy of the NH source, you can fix the bug by changing NHibernate/Mapping/ByCode/PropertyPath.cs line #66 from:

    return hashCode == other.GetHashCode();

    To:

    return hashCode == other.GetHashCode() && ToString() == other.ToString();

    Please check out the Google Group for full details of the issue.

    0 讨论(0)
提交回复
热议问题