Skip to content

Commit

Permalink
refactor: CascadeType.Remove 영속성 전이를 통해 부모 테이블이 삭제될 때 자식 테이블도 같이 삭제되도…
Browse files Browse the repository at this point in the history
…록 수정
  • Loading branch information
jschoi-96 committed Mar 25, 2024
1 parent 228a9ae commit 59dd802
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/balancetalk/module/comment/domain/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public class Comment extends BaseTimeEntity {
@JoinColumn(name = "parent_id")
private Comment parent;

@OneToMany(mappedBy = "comment", cascade = CascadeType.REMOVE)
@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL)
private List<CommentLike> likes = new ArrayList<>();

@OneToMany(mappedBy = "comment", cascade = CascadeType.REMOVE)
@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL)
private List<Report> reports = new ArrayList<>();

public void updateContent(String content) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/balancetalk/module/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Member extends BaseTimeEntity implements UserDetails {
@Column(nullable = false)
private Role role;

@OneToMany(mappedBy = "member", cascade = CascadeType.REMOVE)
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Post> posts = new ArrayList<>();

@OneToMany(mappedBy = "member")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class BalanceOption {
@JoinColumn(name = "post_id")
private Post post;

@OneToMany(mappedBy = "balanceOption", cascade = CascadeType.REMOVE)
@OneToMany(mappedBy = "balanceOption", cascade = CascadeType.ALL)
private List<Vote> votes = new ArrayList<>();

public int voteCount() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/balancetalk/module/post/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ public class Post extends BaseTimeEntity {
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<BalanceOption> options = new ArrayList<>();

@OneToMany(mappedBy = "post", cascade = CascadeType.REMOVE)
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<PostLike> likes = new ArrayList<>();

@Formula("(select count(*) from post_like where post_like.post_id = post_id)")
private long likesCount;

@OneToMany(mappedBy = "post", cascade = CascadeType.REMOVE)
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<Comment> comments = new ArrayList<>();

@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<PostTag> postTags = new ArrayList<>();

@OneToMany(mappedBy = "post", cascade = CascadeType.REMOVE)
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<Bookmark> bookmarks = new ArrayList<>();

@OneToMany(mappedBy = "post", cascade = CascadeType.REMOVE)
@OneToMany(mappedBy = "post", cascade = CascadeType.ALL)
private List<Report> reports = new ArrayList<>();

public boolean isCasual() {
Expand Down

0 comments on commit 59dd802

Please sign in to comment.