From c5e675ce6614d8907f398b17bcffb6234a9930eb Mon Sep 17 00:00:00 2001 From: johnniang Date: Thu, 21 Mar 2019 22:05:34 +0800 Subject: [PATCH] Customize PostTag#equals and PostTag#hashCode --- .../cc/ryanc/halo/model/entity/PostTag.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/cc/ryanc/halo/model/entity/PostTag.java b/src/main/java/cc/ryanc/halo/model/entity/PostTag.java index 304f4c34d..2420c329a 100644 --- a/src/main/java/cc/ryanc/halo/model/entity/PostTag.java +++ b/src/main/java/cc/ryanc/halo/model/entity/PostTag.java @@ -1,16 +1,16 @@ package cc.ryanc.halo.model.entity; -import cc.ryanc.halo.utils.DateUtils; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.ToString; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; import javax.persistence.*; -import java.util.Date; +import java.util.Objects; /** + * Post tag entity. + * * @author : RYAN0UP * @date : 2019-03-12 */ @@ -20,7 +20,6 @@ import java.util.Date; @SQLDelete(sql = "update post_tags set deleted = true where id = ?") @Where(clause = "deleted = false") @ToString -@EqualsAndHashCode(callSuper = true) public class PostTag extends BaseEntity { @Id @@ -45,4 +44,19 @@ public class PostTag extends BaseEntity { super.prePersist(); id = null; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; + PostTag postTag = (PostTag) o; + return Objects.equals(postId, postTag.postId) && + Objects.equals(tagId, postTag.tagId); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), postId, tagId); + } }