I’d like to use Apache commons HashCodeBuilder and EqualsBuilder for overriding hashCode() and equals() method in POJO’s. As per hibernate documentation the identifier value should not be a part of hashCode method. In such a case, I won’t be able to use Apache’s builders as they would include the identifier value too.
What should I do? IDE’s like intelliJ generate the hashCode functions but I don’t want to depend on them. Is there any other library I can use?
The
reflectionHashCodemethod has a variant which allows you to specify excluded fields. As does reflectionEquals. They should help.