c# - Is there a sample why Equals/GetHashCode should be overwritten in NHibernate? -


I get lots of posts where it is explained that one should always override the same / gatehashcode on the NHibernate unit class . If I do not use the group, is it really necessary?

I can not get a sample only, where it is shown that the missing equivalent / gatehashcode can cause unexpected and incorrect behavior. It's strange that everyone says that it is necessary, but no one can provide a sample which why need it.

Recently was selecting N + 1 about NHibernate, even if Fetch specified same / GetHashCode missing problem with the implementation.

Any other similar answer links.

Override equal / GetHashCode here.





edit

You need to override them all the time is not. If you are using composite keys, multiple sessions may be required with different entities or stateless sessions.

If you are working with only one session, then NHE Burnett stores the entities in the first level cache using an identity map. The unit of that case is compared by comparing the comparison ID.

In the above cases (separate entity, Stateless session), NHBnet has compared the actual institutions, and not their ID by default, Object.Equals gives contextuality So two objects are the same, if they point to the exact same example. You can have two examples with the same identity, but Object.Equals will return false for them entity :

Contrary to the object, which is not defined by its features, but based on the thread of continuity and its identity

The Zebus hibernate wiki has equal and hashcode with some code examples.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -