강의

멘토링

커뮤니티

Inflearn Community Q&A

parkht0742's profile image
parkht0742

asked

Developing Spring and JPA based web applications

Processing Profile Update

updateProfile에 영속성컨텍스트

Written on

·

292

0

안녕하세요. 

updateProfile 메소드 내에 account 객체를 persistence로 만드는 방법과 관련해서 아래 소스와 같이 작성했는데요.

제가 생각한 것은 Id로 조회를 한 객체는 Persistence 상태이고, 값을 수정하면 update가 될것이라고 생각해서 작성했는데 update가 되지 않아 원인을 여쭤보고자 질문남깁니다.

답변 부탁드립니다. 감사합니다.

public void updateProfile(Account account, Profile profile) {
	Optional<Account> byId = accountRepository.findById(account.getId());
	Account reAccount = byId.get();
	reAccount.setBio(profile.getBio());
	reAccount.setUrl(profile.getUrl());
	reAccount.setOccupation(profile.getOccupation());
	reAccount.setLocation(profile.getLocation());
}
springspring-bootthymeleafJPAjava

Answer 2

0

parkht님의 프로필 이미지
parkht
Questioner

안녕하세요. @Transactional을 적용하니까 select 후에 update되는 것을 확인했습니다. 답변 감사합니다.

0

whiteship님의 프로필 이미지
whiteship
Instructor

이 코드만 봐서는 알기가 어려운데요. 저 코드에 @Transactional이 적용되어 있나요?

parkht0742's profile image
parkht0742

asked

Ask a question