Spring
Spring_Entity : mappedBy , cascade
주탱2
2022. 9. 15. 16:35
public class Answer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
//...(중략)
@ManyToOne //question : 한개 , answer : 여러개
private Question question;
}
public class Question {
//...(중략)
@OneToMany(mappedBy = "question" , cascade = CascadeType.REMOVE)
private List<Answer> answerList;
}
//mappedBy : 참조 엔티티의 속성명 (question)
//cascade = CascadeType.REMOVE : 질문 삭제 시 연결된 답변 모두 삭제