Customize PostCategory#equals and PostTag#hashCode

pull/137/head
johnniang 2019-03-21 22:07:07 +08:00
parent c5e675ce66
commit 3d80e34215
1 changed files with 16 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import org.hibernate.annotations.Where;
import javax.persistence.*;
import java.util.Date;
import java.util.Objects;
/**
* Post category entity.
@ -21,7 +22,6 @@ import java.util.Date;
@Where(clause = "deleted = false")
@Data
@ToString
@EqualsAndHashCode(callSuper = true)
public class PostCategory extends BaseEntity {
@Id
@ -46,4 +46,19 @@ public class PostCategory 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;
PostCategory that = (PostCategory) o;
return categoryId.equals(that.categoryId) &&
postId.equals(that.postId);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), categoryId, postId);
}
}