-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommentEntity.java
More file actions
64 lines (52 loc) · 1.97 KB
/
Copy pathCommentEntity.java
File metadata and controls
64 lines (52 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package demo.codeexample.comment;
import demo.codeexample.task.infrastructure.adapters.out.persistence.TaskEntity;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.proxy.HibernateProxy;
import java.time.LocalDateTime;
import java.util.Objects;
@Getter
@Setter
@NoArgsConstructor
@Entity
public class CommentEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Setter(AccessLevel.NONE)
private Long id;
@Column(nullable = false, length = 300)
private String content;
@Column(nullable = false)
private Long writerId;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "task_id")
private TaskEntity task;
@Column(nullable = false, updatable = false)
private LocalDateTime createdAt;
public CommentEntity(String content, Long writerId, TaskEntity task) {
this.content = content;
this.writerId = writerId;
this.task = task;
}
@PrePersist
protected void onCreate() {
this.createdAt = LocalDateTime.now();
}
@Override
public final boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
if (thisEffectiveClass != oEffectiveClass) return false;
CommentEntity that = (CommentEntity) o;
return getId() != null && Objects.equals(getId(), that.getId());
}
@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}