인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

howistigoing's profile image
howistigoing

asked

Java ORM Standard JPA Programming - Basics

Persistence Propagation (CASCADE) and Orphan Object

영속성 전이 + 고아객체

Resolved

Written on

·

259

2

안녕하세요 영한님!

영속성 전이 + 고아객체에 대해서 질문이 있습니다.!

강의 20분12초 쯤부터 설명하시는 내용을 들어보면

 

CascadeType.ALL + orphanRemovel = true를 설정하게 되면

부모 엔티티를 통해서 자식의 생명주기를 관리 할 수 있다고 말씀하셨는데

 

그러면 아래와 같은 코드가 있을때

 

 

public Parent findParent(Long id) {

    return em.find(Parent.class, id);

}

 

 

public void deleteParent(String name) {

 

    em.createQuery("delete from Parent p" +

            " where p.name = :name")

            .setParameter("name", name)

            .executeUpdate();

}

 

@Transactional

public void delete() {

    Parent parent = parentRepository.findParent(1L);

    parentRepository.deleteParent(parent.getName());

}

 

 

이런식으로 코드를 작성하면 자식도 함께 삭제가 안되는게 맞는 걸까요?

위와 같이 진행하면 무결성 참조 에러가 발생하여서 질문 남깁니다..! 😭

Referential integrity constraint violation

 

 

 

감사합니다.

 

장세웅 드림.

 

 

 

영속성전이+고아객체javaJPA

Answer 1

1

yh님의 프로필 이미지
yh
Instructor

안녕하세요. 장세웅님

이렇게 직접 JPQL을 작성해서 한번에 엔티티를 변경하거나 제거하는 것을 벌크 연산이라고 하는데요. 벌크 연산에서는 cascade를 지원하지 않습니다.

감사합니다.

howistigoing님의 프로필 이미지
howistigoing
Questioner

감사합니다.^^

howistigoing's profile image
howistigoing

asked

Ask a question