jpa에서 modify도 save인 이유

taehoon·2023년 11월 30일

jpa에서 save는 pk로 row와 객체를 구분한다. 따라서 save를 했을 때 pk가 같다면 db에서는 업데이트가 이루어진다.

public void modify(Question question, String subject, String content) {
        question.setSubject(subject);
        question.setContent(content);
        question.setModifyDate(LocalDateTime.now());
        this.questionRepository.save(question);
    }

위 메서드를 실행했을 때 아래에 있는 쿼리가 실행된다.

Hibernate: 
    update
        question 
    set
        author_id=?,
        content=?,
        create_date=?,
        modify_date=?,
        subject=? 
    where
        id=?
profile
건강

0개의 댓글