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=?