게시글 1을 삭제 한다고 해서 자동으로 그에 대한 댓글들이 삭제 되는 것이 아니다.
@OneToMany, @ManyToOne과 같은 매핑 어노테이션의 cascade를 통해 이를 지정할 수 있고,
javax.persistence.CascadeType에 여러 cascade type이 정의되어 있다.
[ FetchType ]
- ALL
cascades all entity state transitions
- PERSIST
cascades the entity persist operation.
- MERGE
cascades the entity merge operation.
- REMOVE
cascades the entity remove operation.
- REFRESH
cascades the entity refresh operation.
- DETACH
cascades the entity detach operation.
부모에서 해당 FetchType이 실행될 때,
자식에게 영속성 전이를 한다고 생각할 수 있다.
(FetchType.REMOVE면 부모가 삭제될 때 자식도 같이 삭제됨)
(FetchType.ALL의 경우 FetchType이 모두 적용)
게시글을 삭제하려 할 경우 게시글만 삭제가 될 것이고
BOARD_ID가 foreign key로 걸려있는 댓글이 남아있기 때문에 SQL에서 에러가 난다.