강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của parkht0742
parkht0742

câu hỏi đã được viết

Phát triển ứng dụng web dựa trên Spring và JPA

Cập nhật hồ sơ

updateProfile에 영속성컨텍스트

Viết

·

288

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

Câu trả lời 2

0

parkht님의 프로필 이미지
parkht
Người đặt câu hỏi

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

0

whiteship님의 프로필 이미지
whiteship
Người chia sẻ kiến thức

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

Hình ảnh hồ sơ của parkht0742
parkht0742

câu hỏi đã được viết

Đặt câu hỏi