@AuthenticationPrincipal를 통해 인증 객체로 가져온 Account 업데이트 시 merge 가 아닌 set 업데이트 문제점
[자문자답]https://www.inflearn.com/questions/311345해당 강의 질문 내역 확인 중 비슷한 질문을 발견하여 참고하여 소스를 변경하였습니다.private void syncAuthenticationUser(Account account) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( new UserAccount(account), account.getPassword(), List.of(new SimpleGrantedAuthority("ROLE_USER"))); SecurityContextHolder.getContext().setAuthentication(token); } @Transactional public void updateProfile(Account account, Profile profile) { Account findAccount = accountRepository.findById(account.getId()) .orElseThrow(IllegalArgumentException::new); modelmapper.map(profile, findAccount); syncAuthenticationUser(findAccount); } 다음과 같이, AccountService의 login() 메서드의 로그인 처리를 위한 Account 객체를 Token에 전달하여 SecurityContextHolder.getContext().setAuthentication(token); 로 등록하는 부분을 따로 메서드로 추출하여 Account 정보를 데이터베이스에 업데이트하는 로직은 업데이트 후 인증 객체를 재등록하는 방식으로 변경하였습니다.해당 방식으로 변경하니 spring security 인증 객체인 Account가 갱신? 되어 조회 폼에서 별도로 Account 객체를 데이터베이스에서 재조회하는 방식으로 진행하지 않아도 모두 정상적으로 데이터가 표출되었습니다.다만, 업데이트가 이루어질 때마다 인증 객체를 재등록하는 방식이 옳은 방식인지는 잘 모르겠습니다.더 좋은 방법이 있다면 알려주시면 감사하겠습니다.