feat: on delete 설정
This commit is contained in:
parent
3027afd059
commit
f628bbbd00
@ -4,6 +4,8 @@ import com.edufocus.edufocus.lecture.entity.Lecture;
|
|||||||
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.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -13,6 +15,8 @@ import java.util.Date;
|
|||||||
@Builder
|
@Builder
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
public class Qna {
|
public class Qna {
|
||||||
|
|
||||||
// 연관관계 주인
|
// 연관관계 주인
|
||||||
|
@ -7,6 +7,8 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
|||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.hibernate.annotations.CreationTimestamp;
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
import org.hibernate.annotations.OnDelete;
|
||||||
|
import org.hibernate.annotations.OnDeleteAction;
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ import java.util.List;
|
|||||||
@Builder
|
@Builder
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
public class Report {
|
public class Report {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@ -50,10 +53,10 @@ public class Report {
|
|||||||
@JoinColumn(name = "reportset_id")
|
@JoinColumn(name = "reportset_id")
|
||||||
private ReportSet reportSet;
|
private ReportSet reportSet;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "report", cascade = CascadeType.REMOVE)
|
@OneToMany(mappedBy = "report", cascade = CascadeType.REMOVE)
|
||||||
private List<Answer> answers;
|
private List<Answer> answers;
|
||||||
|
|
||||||
public ReportResponse makeReportResponse(){
|
public ReportResponse makeReportResponse() {
|
||||||
return ReportResponse.builder()
|
return ReportResponse.builder()
|
||||||
.reportId(id)
|
.reportId(id)
|
||||||
.name(user.getName())
|
.name(user.getName())
|
||||||
|
@ -5,10 +5,9 @@ import com.edufocus.edufocus.quiz.entity.QuizSet;
|
|||||||
import com.edufocus.edufocus.report.entity.dto.ReportSetResponse;
|
import com.edufocus.edufocus.report.entity.dto.ReportSetResponse;
|
||||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import org.hibernate.annotations.ColumnDefault;
|
import org.hibernate.annotations.*;
|
||||||
import org.hibernate.annotations.CreationTimestamp;
|
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
|
||||||
import org.springframework.data.annotation.CreatedDate;
|
import org.springframework.data.annotation.CreatedDate;
|
||||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||||
|
|
||||||
@ -19,7 +18,6 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Getter
|
@Getter
|
||||||
@Builder
|
@Builder
|
||||||
@ -27,6 +25,7 @@ import java.util.UUID;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EntityListeners(AuditingEntityListener.class)
|
@EntityListeners(AuditingEntityListener.class)
|
||||||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
|
||||||
|
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||||
public class ReportSet {
|
public class ReportSet {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(generator = "UUID")
|
@GeneratedValue(generator = "UUID")
|
||||||
@ -60,7 +59,7 @@ public class ReportSet {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long findUserId(){
|
public long findUserId() {
|
||||||
return lecture.getUser().getId();
|
return lecture.getUser().getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user