-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathComment.java
More file actions
41 lines (36 loc) · 942 Bytes
/
Comment.java
File metadata and controls
41 lines (36 loc) · 942 Bytes
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
package com.example.devSns.entity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;
import lombok.*;
import java.time.LocalDateTime;
@Entity
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Comment{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String content;
private String username;
private LocalDateTime createdAt;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(
name="post_id",
nullable = false,
foreignKey = @ForeignKey(name = "fk_diary_user_id_ref_user_id")
)
@JsonBackReference
private Post post;
@PrePersist
public void onCreate(){
createdAt = LocalDateTime.now();
}
public void update(String content){
this.content = content;
}
public void assignTo(Post post){
this.post = post;
}
}