Skip to content

Commit

Permalink
Add: cascade = CascadeType.REMOVE
Browse files Browse the repository at this point in the history
  • Loading branch information
5w31892p committed Jan 3, 2023
1 parent 9b4e3c6 commit 8dffc9d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests().requestMatchers(
new AntPathRequestMatcher("/**")).permitAll()
.and()
// h2콘솔 csrf 검증 안한다.
// .csrf().ignoringAntMatchers("/h2-console/**")// h2콘솔 csrf 검증 안한다.
// .and()
.headers()
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/sparta/nbcamblog/entity/Blog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -39,7 +40,7 @@ public class Blog extends Timestamped {
@JoinColumn(name = "USER_ID", nullable = false)
private BlogUser user;

@OneToMany(mappedBy = "blog")
@OneToMany(mappedBy = "blog", cascade = CascadeType.REMOVE) // 게시물 삭제 시 해당 코멘트 모두 삭제
private List<Comment> commentList = new ArrayList<>();


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/sparta/nbcamblog/entity/BlogUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import lombok.Getter;
Expand All @@ -34,7 +34,7 @@ public class BlogUser {
@Enumerated(value = EnumType.STRING)
private UserRoleEnum role;

@OneToMany
@OneToMany(cascade = CascadeType.REMOVE) // 삭제시 해당 블로그 모두 함께 삭제
private List<Blog> blogList = new ArrayList<>();

public BlogUser (String username, String password, UserRoleEnum role) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/sparta/nbcamblog/entity/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
Expand Down

0 comments on commit 8dffc9d

Please sign in to comment.