@Transactional
@Override
public ApiResponse<Void> updateMatching(Long matchingId, MatchingRequest.MatchingRequestUpdate updateReqDto, AuthUser authUser) {
try {
User user = User.fromAuthUser(authUser);
Matching findMatching = matchingRepository.findByIdWithOptimisticLock(matchingId);
MatchingValidator.isMe(user.getId(),findMatching.getUser().getId());
Matching updateMatching = Matching.builder()
.id(findMatching.getId())
.user(findMatching.getUser())
.portfolio(findMatching.getPortfolio())
.outsourcing(findMatching.getOutsourcing())
.status(updateReqDto.status())
.version(findMatching.getVersion())
.build();
matchingRepository.save(updateMatching);
return ApiResponse.of(MATHCING_SUCCESS);
} catch (ObjectOptimisticLockingFailureException e) {
log.error("동시성 문제 발생 ! {}", e.getMessage());
}
return null;
}




... 삽질중 ...
원인은 다음과 같다
삽질 끝!
@Transactional
@Override
public ApiResponse<Void> updateMatching(Long matchingId, MatchingRequest.MatchingRequestUpdate updateReqDto, AuthUser authUser) {
try {
MatchingValidator.isNotCompany(authUser);
Matching findMatching = findById(matchingId);
findMatching.statusChange(updateReqDto.status());
matchingRepository.flush();
return ApiResponse.of(MATHCING_SUCCESS);
} catch (OptimisticLockingFailureException e) {
log.error("Optimistic lock error: {}", e.getMessage());
throw new MatchingException(MATCHING_LOCK);
}
}
