From 9642ddd2ce07eaea03319a10fdf96c3683b934f1 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 12 Jan 2020 20:30:47 +0100 Subject: Implement equals() and hashCode for composite ID classes. Change-Id: I7fd6be62f62f8dc43fa2863f52287654d307e8e0 --- .../eu/mulk/mulkcms2/entity/ArticleBranchTipPK.java | 18 ++++++++++++++++++ .../entity/ArticleRevisionCharacteristicPK.java | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'src') diff --git a/src/main/java/eu/mulk/mulkcms2/entity/ArticleBranchTipPK.java b/src/main/java/eu/mulk/mulkcms2/entity/ArticleBranchTipPK.java index 2508f87..6472a8d 100644 --- a/src/main/java/eu/mulk/mulkcms2/entity/ArticleBranchTipPK.java +++ b/src/main/java/eu/mulk/mulkcms2/entity/ArticleBranchTipPK.java @@ -1,6 +1,7 @@ package eu.mulk.mulkcms2.entity; import java.io.Serializable; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Id; @@ -28,4 +29,21 @@ public class ArticleBranchTipPK implements Serializable { public void setRevisionId(int revisionId) { this.revisionId = revisionId; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ArticleBranchTipPK)) { + return false; + } + ArticleBranchTipPK that = (ArticleBranchTipPK) o; + return articleId == that.articleId && revisionId == that.revisionId; + } + + @Override + public int hashCode() { + return Objects.hash(articleId, revisionId); + } } diff --git a/src/main/java/eu/mulk/mulkcms2/entity/ArticleRevisionCharacteristicPK.java b/src/main/java/eu/mulk/mulkcms2/entity/ArticleRevisionCharacteristicPK.java index 2da588e..edaaff1 100644 --- a/src/main/java/eu/mulk/mulkcms2/entity/ArticleRevisionCharacteristicPK.java +++ b/src/main/java/eu/mulk/mulkcms2/entity/ArticleRevisionCharacteristicPK.java @@ -1,6 +1,7 @@ package eu.mulk.mulkcms2.entity; import java.io.Serializable; +import java.util.Objects; import javax.persistence.Id; public class ArticleRevisionCharacteristicPK implements Serializable { @@ -24,4 +25,22 @@ public class ArticleRevisionCharacteristicPK implements Serializable { public void setArticleRevisionId(int articleRevisionId) { this.articleRevisionId = articleRevisionId; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ArticleRevisionCharacteristicPK)) { + return false; + } + ArticleRevisionCharacteristicPK that = (ArticleRevisionCharacteristicPK) o; + return articleRevisionId == that.articleRevisionId + && Objects.equals(characteristic, that.characteristic); + } + + @Override + public int hashCode() { + return Objects.hash(characteristic, articleRevisionId); + } } -- cgit v1.2.3