IT'S DO
Published 2022. 8. 26. 13:16
업데이트 시 code+1 개발/JPA
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();
    }*/

'개발 > JPA' 카테고리의 다른 글

Entity 클래스는 유의 사항  (0) 2022.08.26
Jpa에서 테이블 내부, 외부  (0) 2022.08.26
jpa increaseCode  (0) 2022.08.26
@Builder  (0) 2022.08.26
JPA jpql을 사용하면서 배운것. 아주 중요. 그리고 나중에 생각 꼭  (0) 2022.08.23
profile

IT'S DO

@멋진놈

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!