Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface CandidateVoteRepository extends JpaRepository<CandidateVote, Lo

boolean existsByUserIdAndPromiseId(Long userId, Long promiseId);

@Modifying(clearAutomatically = true, flushAutomatically = true)
@Modifying(flushAutomatically = true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

clearAutomatically = true 옵션을 제거하면 벌크 삭제 연산 후에도 영속성 컨텍스트가 유지되어 LazyInitializationException을 방지할 수 있지만, 영속성 컨텍스트와 데이터베이스 간의 데이터 불일치(Stale State) 문제가 발생할 수 있는 점에 유의해야 합니다. 특히 Promise 엔티티가 CandidateVote 엔티티들과 @OneToMany 관계를 맺고 있고 해당 컬렉션이 이미 영속성 컨텍스트에 로드되어 있다면, DB에서 삭제된 데이터가 메모리상의 컬렉션에는 여전히 남아있게 됩니다. 이 트랜잭션의 남은 로직에서 해당 컬렉션을 참조하거나 삭제된 엔티티를 다시 조회하지 않는지 확인이 필요하며, 만약 데이터 정합성이 중요하다면 연산 후 필요한 엔티티를 명시적으로 다시 조회하는 방안을 고려해 보시기 바랍니다.

@Query("delete from CandidateVote cv where cv.promise.id = :promiseId")
void deleteAllByPromiseId(@Param("promiseId") Long promiseId);
}
Loading