feat: cascade 설정

This commit is contained in:
박정민 2024-08-09 16:35:18 +09:00
parent 5bc56fc2a7
commit 4d479d702e
4 changed files with 14 additions and 8 deletions

View File

@ -64,7 +64,7 @@ public class Board {
@OnDelete(action = OnDeleteAction.CASCADE) @OnDelete(action = OnDeleteAction.CASCADE)
private Lecture lecture; private Lecture lecture;
@OneToMany(mappedBy = "board", cascade = CascadeType.ALL) @OneToMany(mappedBy = "board")
private List<Comment> comments; private List<Comment> comments;
public ResponseBoardSummaryDto makeSummaryDto() { public ResponseBoardSummaryDto makeSummaryDto() {

View File

@ -10,6 +10,8 @@ import lombok.Builder;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.UpdateTimestamp; import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
@ -46,6 +48,7 @@ public class Comment {
@ManyToOne @ManyToOne
@JoinColumn(name = "board_id") @JoinColumn(name = "board_id")
@OnDelete(action = OnDeleteAction.CASCADE)
Board board; Board board;
public ResponseCommentDto makeCommentDto(long userId) { public ResponseCommentDto makeCommentDto(long userId) {

View File

@ -7,6 +7,8 @@ import com.edufocus.edufocus.report.entity.vo.ReportSet;
import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.entity.vo.User;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.*; import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.util.UUID; import java.util.UUID;
@ -22,11 +24,12 @@ public class Registration {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id; private long id;
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne
@JoinColumn(name = "user_id") @JoinColumn(name = "user_id")
private User user; private User user;
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "lecture_id") @JoinColumn(name = "lecture_id")
private Lecture lecture; private Lecture lecture;

View File

@ -21,7 +21,7 @@ spring.datasource.username=${USER_NAME}
spring.datasource.password=${USER_PASSWORD} spring.datasource.password=${USER_PASSWORD}
spring.mvc.pathmatch.matching-strategy=ant_path_matcher spring.mvc.pathmatch.matching-strategy=ant_path_matcher
spring.jpa.database=mysql spring.jpa.database=mysql
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true spring.jpa.show-sql=true
spring.jpa.properties.hibernate.jdbc.time_zone=Asia/Seoul spring.jpa.properties.hibernate.jdbc.time_zone=Asia/Seoul
management.endpoints.web.exposure.include=health,info management.endpoints.web.exposure.include=health,info