개발/JPA
업데이트 시 code+1
멋진놈
2022. 8. 26. 13:16
728x90
업데이트 시에 code+1 추가(현재는 안씀)
*/
@Modifying
@Query("update Revision p set p.code = p.code + 1 where p.event.id = :id")
Integer updateCode(@Param("id") Long id);
Integer updateCode(Long id) throws Exception;
@Transactional
public Integer updateCode(Long id) {
return revisionRepository.updateCode(id);
}
외에도 이를 구현 하기 위해서 막 썼었는데,
나중에 필요할 수도 있으니 이력
/* @Transactional
public RevisionResponseDto findById(final Long eventId) throws Exception {
Revision entity = revisionRepository.findById(eventId).orElseThrow(() -> new CustomException(ErrorCode.POSTS_NOT_FOUND));
entity.increaseCodes();
return new RevisionResponseDto(entity);
}*/
/* @Transactional
public Long findById2(final Long eventId) throws Exception {
Event event = eventRepository.findById(eventId).orElseThrow(() -> new IllegalArgumentException("해당 eventId가 없습니다. id=" + eventId));
Revision entity = revisionRepository.findById(eventId).orElseThrow(() -> new CustomException(ErrorCode.POSTS_NOT_FOUND));
entity.increaseCodes();
return new entity.getCode();
}*/