英文:
Is it safe to override hashCode() and equals() on Mongo entity class
问题
你能帮助我吗?
我有一个Mongo实体,其中包含Mongo自动生成的_id
。
我想要一种更容易的机制来比较这些实体,排除_id
以进行比较。
我正在使用Lombok,所以添加了注解
@EqualsAndHashCode(exclude=“_id”)
我没有发现这对于从Mongo创建/保存/查询这些项有任何影响,但也许我漏掉了一些东西
从equals()
和hashCode()
中排除_id
是否可以?这会影响Mongo如何保存它们吗?
(我在该实体上有另一个业务键,但无论如何我需要自动生成_id
)
英文:
Can you please help me?
I have Mongo entity which contains _id
self generated by Mongo.
I would like to have easier mechanism of comparing these entities by excluding this _id
from comparison.
I’m using Lombok, so added annotation
@EqualsAndHashCode(exclude=“_id”)
I did not find any influence of this on create/save/query these items from Mongo, but maybe I miss something
Is it OK to exclude _id
from equals()
and hashCode()
? Does it take influence on how they will be saved by Mongo?
(I have another buisiness key on that entity but I need _id
self generated anyway)
专注分享java语言的经验与见解,让所有开发者获益!
评论