Do I need to check all field in equals method of model class in JPA?
3 answers
No, there is no need to put all your fields in the equals method just because you are using JPA. Actually, specific JPA fields that you can ignore.
You need to decide what makes sense for your application, but it is quite common to exclude @Id and @Version fields. Include only those fields that distinguish one instance of an object from another: essentially the fields that form the key.
+3
a source to share
Not always. You should clearly see which fields form your own (business) key and only compare those fields. Sometimes all fields form their own key, sometimes they don't.
Read this discussion on the hibernate forum about the equals and hashcode implementation strategy .
+2
a source to share