Is it necessary to check all the field in equals method of model class in JPA, or can I use only id?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it’s not necessary to put all of your fields in the equals method just because you’re using JPA. In fact, JPA specific fields you may want to ignore.
You need to decide what makes most sense for your application, but it’s quite common to exclude your @Id and @Version fields. Include only those fields that differentiate one instance of an object from another: essentially the fields that form the key.