Skip to content

Commit

Permalink
HHH-3771 - Best practice for equals implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmihalcea committed Oct 6, 2016
1 parent 0ba1d69 commit 5ea187f
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -257,6 +257,14 @@ include::{sourcedir}/entity/listing9.java[]

As you can see the question of equals/hashCode is not trivial, nor is there a one-size-fits-all solution.

[TIP]
====
Although using a natural-id is best for `equals` and `hashCode`, sometimes you only have the entity identifier that provides a unique constraint.
It's possible to use the entity identifier for equality check, but it needs a workaround.
Check out https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-entity-identifier/[this article for more details about the best way of mapping `equals` and `hashCode` using the entity identifier].
====

For details on mapping the identifier, see the <<chapters/domain/identifiers.adoc#identifiers,Identifiers>> chapter.

[[entity-pojo-optlock]]
Expand Down

0 comments on commit 5ea187f

Please sign in to comment.