org.hibernate.PropertyValueException: not-null property references a null or transient value
문제 원인
@Service
@RequiredArgsConstructor
@Transactional
public class CommentServiceImpl implements CommentService{
private final CommentRepository commentRepository;
@Override
public Comment updateComment(Comment comment) {
Comment findComment = findVerifiedComment(comment.getCommentId());
checkStudyStatusIsRecruitProgress(findComment.getStudy());
if (findComment.getCommentStatus() == Comment.CommentStatus.COMMENT_DELETE)
throw new BusinessLogicException(ExceptionCode.COMMENT_DELETED);
Optional.ofNullable(comment.getContent())
.ifPresent(content -> findComment.setContent(content));
return commentRepository.save(comment); // comment 대신 findComment를 저장하여야 함 (일종의 오타)
}
...
}
해결 방안