问题描述
阅读之后,我不想完全覆盖equals()和hashCode() 。
After reading this article , im bending toward not overriding equals() and hashCode() altogether.
在该文章的摘要中,关于所有栏目的无eq / hC,唯一的后果是我无法进行比较操作,如:
In the summary of that article, concerning the no eq/hC at all column, the only consequence is that i couldnt do the comparison operations like :
- 在分离实体的List中包含(),或
- 比较来自不同会话的相同实体
并期望得到正确的结果。
and expect the correct result.
但我仍有疑问,并希望请问一下你的经历是否完全跳过equals和hashCode是不好的做法以及我现在还不知道的其他后果。
But im still in doubt and would like to ask your experiences about this whether it is a bad practice to skip equals and hashCode altogether and what other consequences that i still dont know for now.
只是另一个信息点,我倾向于使用List Collections over Set。而我的假设是,当存储在List中时,我真的不需要覆盖hashCode并且相等。
Just another point of information, im bending towards using List Collections over Set. And my assumption is that i dont really need to override hashCode and equal when storing in a List.
推荐答案
阅读这篇非常好的文章关于这个问题:。
Read this very nice article on the subject: Don't Let Hibernate Steal Your Identity.
文章的结论是这样的:
这篇关于JPA:没有覆盖实体中的equals()和hashCode()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!