Skip to content

Commit 5ea187f

Browse files
committed
HHH-3771 - Best practice for equals implementation
1 parent 0ba1d69 commit 5ea187f

File tree

1 file changed

+8
-0
lines changed
  • documentation/src/main/asciidoc/userguide/chapters/domain

1 file changed

+8
-0
lines changed

documentation/src/main/asciidoc/userguide/chapters/domain/entity.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,14 @@ include::{sourcedir}/entity/listing9.java[]
257257

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

260+
[TIP]
261+
====
262+
Although using a natural-id is best for `equals` and `hashCode`, sometimes you only have the entity identifier that provides a unique constraint.
263+
264+
It's possible to use the entity identifier for equality check, but it needs a workaround.
265+
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].
266+
====
267+
260268
For details on mapping the identifier, see the <<chapters/domain/identifiers.adoc#identifiers,Identifiers>> chapter.
261269

262270
[[entity-pojo-optlock]]

0 commit comments

Comments
 (0)