Is it safe to override hashCode() and equals() on Mongo entity class

Viewed 268

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)

0 Answers
Related