Hibernate assumes that you only include the business key / candidate key in the equals implementation. Including the id field in the equals implementation can have negative consequences if you create an id field. Hibernate only assigns an identifier when saving an object (if you use the generated identifiers). For example, if your new unsaved domain object is located in a HashSet and you save the domain, it will generate and assign an identifier to the domain, the hash code of the domain will change if your equals / hashcode is based on the id field and your domain will be lost in the set.
It is assumed that you implement equals using unique immutable fields.
See links
source share