0
public Optional<UserDTO> updateUser(UserDTO userDTO) {
        return Optional.of(userRepository
            .findOne(userDTO.getId()))
            .map(user -> {
                user.setLogin(userDTO.getLogin());
                user.setFirstName(userDTO.getFirstName());
                user.setLastName(userDTO.getLastName());
                user.setEmail(userDTO.getEmail());
                user.setImageUrl(userDTO.getImageUrl());
                user.setActivated(userDTO.isActivated());
                user.setLangKey(userDTO.getLangKey());
                Set<Authority> managedAuthorities = user.getAuthorities();
                managedAuthorities.clear();
                userDTO.getAuthorities().stream()
                    .map(authorityRepository::findOne)
                    .forEach(managedAuthorities::add);
                cacheManager.getCache(UserRepository.USERS_BY_LOGIN_CACHE).evict(user.getLogin());
                cacheManager.getCache(UserRepository.USERS_BY_EMAIL_CACHE).evict(user.getEmail());
                log.debug("Changed Information for User: {}", user);
                return user;
            })
            .map(UserDTO::new);
    }

I have a problem with the function Optional<UserDTO> updateUser(UserDTO userDTO)

There is no userRepository.save(user); but the save is successful.

How should I understand where this is saved?!

  • 2
    Does this answer your question? [Transactional saves without calling update method](https://stackoverflow.com/questions/8190926/transactional-saves-without-calling-update-method) You don't need to call "save", the entity is managed by JPA and this is in a transaction, so it is saved automatically when the transaction is closed and the session is flushed. – Gaël Marziou Nov 12 '20 at 09:45
  • Oh yes thank you, this is exactly what i want – 刘Little_Y Nov 13 '20 at 04:28

0 Answers0