Skip to content

Soft Delete 정리 및 DataJpaTest 테스트코드 작성 #88

Description

@bbeomgeun

이슈 내용

  • 현재 Soft Delete를 두 번에 나눠서 하고 있음. (Member <-> Family가 N:M이라)
  • Member에 종속된 FamilyMember와 CareLog를 cascade.Remove를 진행
  • Family에 종속된 Pet -> PetCare -> PetCareAlarm를 cascade.Remove를 진행
  • 삭제해주는 순서에 따라서 soft delete시 생성되는 update 쿼리에 객체의 연관관계가 끊기면서 id가 null로 update되서 SQLException이 발생한다 (순서가 바뀌면 가족관련이 먼저 삭제되서 의존되는 familyMember와 carelogList의 id가 null이 되어 update쿼리가 발생함)
  • 멤버부터 삭제해주면 연관관계가 상관이 없어지고, 이후 가족에 종속된 객체들을 삭제해준다.

To-do

  • Repository 테스트를 통해 Persist 정상 작동 확인
  • repository.delete 시 연관관계가 끊기는지 확인하기
  • 끊긴다면 이후 orphanRemoval 옵션을 통해서 자동 삭제할 수 있는지?
  • orphanRemoval은 부모와 자식 연관관계를 삭제하면 자동으로 자식 엔티티가 삭제됨 (관계를 자르면 자식 고아 취급)

참고 사항

  • isDeleted = True로 필드만 update하는데 왜 id가 null로 들어가는지, 연관관계가 끊어지는건지?
  • 내가 SQLDelete로 동작만 바꾼 거고 delete 시 원래 연관관계가 끊기는지?
  • soft delete 정리글
  • orphanRemoval

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugfixSomething isn't workingtodo

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions