반응형 optimisticlockexception1 JPA - 특정 FK(외래 키)에 대한 엔티티 리스트 업데이트 문제 해결 (OptimisticLockException) 요구사항JPA에서 특정 FK(외래 키)에 대한 엔티티 리스트를 업데이트할 때, 다음과 같은 로직이 필요하다.요청으로 받은 리스트의 엔티티들은 업데이트 또는 신규 추가되어야 함.기존 DB에는 있지만 요청 리스트에는 없는 엔티티들은 삭제되어야 함.문제 코드 (예시)public void updateEntityList(Long parentId, List childDtoList){ long result = childRepository.deleteByParentId(parentId); if(result > 0){ childDtoList.stream().forEach(childDto -> childRepository.save(childMapper.to.. 2025. 2. 7. 이전 1 다음 반응형