Skip to content

Commit 14b67e7

Browse files
committed
feat : user 엔티티 해시코드 오버라이딩 추가
1 parent 47c5a58 commit 14b67e7

File tree

1 file changed

+12
-0
lines changed
  • src/main/java/com/back/domain/user/entity

1 file changed

+12
-0
lines changed

src/main/java/com/back/domain/user/entity/User.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.ArrayList;
1515
import java.util.Collection;
1616
import java.util.List;
17+
import java.util.Objects;
1718

1819
@Entity
1920
@Table(name = "users") // 예약어 충돌 방지를 위해 "users" 권장
@@ -70,6 +71,17 @@ public class User {
7071
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
7172
private List<PostLike> postLikes = new ArrayList<>();
7273

74+
@Override
75+
public boolean equals(Object o) {
76+
if (o == null || getClass() != o.getClass()) return false;
77+
User user = (User) o;
78+
return Objects.equals(id, user.id);
79+
}
80+
81+
@Override
82+
public int hashCode() {
83+
return Objects.hashCode(id);
84+
}
7385

7486
public boolean isAdmin() {
7587
return "ADMIN".equalsIgnoreCase(role);

0 commit comments

Comments
 (0)