title: Updating user info (Spring boot)
body: <p>I have a entity class that contains userinfo :</p>
  
  <pre><code>@Entity
  @Table(name = "user")
  @PasswordMatch(message="{register.repeatPassword.mismatch}") 
  @DynamicUpdate
  public class SiteUser {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "id")
  private Long id;
  
  @Column(name = "email", unique=true)
  @Email(message="{register.email.invalid}") 
  @NotBlank(message="{register.email.invalid}")
  private String email;
  
  @Transient  
  @Size(min=5, max=15, message="{register.password.size}")
  private String plainPassword;
  
  @Transient
  private String repeatPassword;
  
  @Column(name = "password", length=60)
  private String password;
  
  @Column(name="enabled")
  private boolean enabled = false;
  
  @Column(name="role", length=20)
  private String role;
  
  @NotNull
  @Column(name="firstname", length=20)
  @Size(min=2, max=20, message="{register.firstname.size}")
  private String firstname;
  
  @NotNull
  @Column(name="surname", length=25)
  @Size(min=2, max=25, message="{register.surname.size}")
  private String surname;
  
  public SiteUser() {
  
  }
  
  public SiteUser(String email, String password, String firstname, String surname) {
      this.email = email;
      this.setPlainPassword(password);
      this.repeatPassword = password;
      this.enabled= true;
      this.firstname= firstname;
      this.surname= surname;
  }
  
  public Long getId() {
      return id;
  }
  
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public String getEmail() {
      return email;
  }
  
  public void setEmail(String email) {
      this.email = email;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public String getRole() {
      return role;
  }
  
  public void setRole(String role) {
      this.role = role;
  }
  
  public String getPlainPassword() {
      return plainPassword;
  }
  
  public void setPlainPassword(String plainPassword) {
      this.password = new BCryptPasswordEncoder().encode(plainPassword);
      this.plainPassword = plainPassword;
  }
  
  public String getRepeatPassword() {
      return repeatPassword;
  }
  
  public void setRepeatPassword(String repeatPassword) {
      this.repeatPassword = repeatPassword;
  }
  
  public boolean isEnabled() {
      return enabled;
  }
  
  public void setEnabled(boolean enabled) {
      this.enabled = enabled;
  }
  
  public String getFirstname() {
      return firstname;
  }
  
  public void setFirstname(String firstname) {
      this.firstname = firstname;
  }
  
  public String getSurname() {
      return surname;
  }
  
  public void setSurname(String surname) {
      this.surname = surname;
  }
  }
  </code></pre>
  
  <p>My problem is that for registering users I added unique and @NotBlank annotations to my email and firstname / lastname columns so now that I want to only update my password I have 2 problems</p>
  
  <p>1- I have to add other fields as hidden in the update form since they can't be empty</p>
  
  <p>2- when i try to update my data using save() method of the Dao I get an error that there is same email in database.</p>
  
  <p>Is there any kind of logical solution for this issue?</p>
  
  <p>====================Update=========================</p>
  
  <p>Controller :</p>
  
  <pre><code>@RequestMapping(value ="/resetPassword", method = RequestMethod.GET)
  ModelAndView resetPasswordMailRecieved(ModelAndView modelAndView,           @RequestParam("t") String tokenString) {
  
      VerificationToken token = userService.getVerificationToken(tokenString);
      SiteUser user = token.getUser();
  
      if(token == null)
      {
          modelAndView.setViewName("redirect:/invalidUser");
          return modelAndView;
      }
  
      Date expirydate = token.getExpiry();
  
      if(expirydate.before(new Date()))
      {
          modelAndView.setViewName("redirect:/expiredToken");
          userService.deleteToken(token);
          return modelAndView;
      }
  
      userService.deleteToken(token);
      modelAndView.getModel().put("user", user);
      modelAndView.setViewName("app.resetPass");
      return modelAndView;
  }
  </code></pre>
  
  <p>jSP file :</p>
  
  <pre><code>&lt;form:form method="post" modelAttribute="user" class="login-form"&gt;
  
                  &lt;form:input type="hidden" path="firstname" /&gt;
                  &lt;form:input type="hidden" path="surname" /&gt;
                  &lt;form:input type="hidden" path="email" /&gt;
  
                  &lt;div class="input-group"&gt;
                      &lt;form:input type="password" path="plainPassword"
                          placeholder="Password" class="form-control" /&gt;
                  &lt;/div&gt;
  
                  &lt;div class="input-group"&gt;
                      &lt;form:input path="repeatPassword" type="password"
                          placeholder="Repeat password" class="form-control" /&gt;
                  &lt;/div&gt;
  
                  &lt;div class="input-group"&gt;
                      &lt;button type="submit" class="btn-primary pull-right"&gt;Change
                          Password&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/form:form&gt;
  </code></pre>
  
  <p>UserDao :</p>
  
  <pre><code>@Repository
  public interface UserDao extends CrudRepository&lt;SiteUser, Long&gt; { 
     SiteUser findByEmail(String email);
  }
  </code></pre>
  
  <p>UserService :</p>
  
  <pre><code>@Service 
  public class UserService implements UserDetailsService {
  @Autowired
  private UserDao userDao;
  
  @Autowired
  PasswordEncoder encoder;
  
  @Autowired 
  private VerificationDao verificationDao; 
  
  public void register(SiteUser user) {
      user.setRole("ROLE_USER");
      userDao.save(user);
  }
  
  @Override
  public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
      SiteUser user = userDao.findByEmail(email);
  
      if (user == null) {
          return null;
      }
  
      List&lt;GrantedAuthority&gt; auth = AuthorityUtils.commaSeparatedStringToAuthorityList(user.getRole());
  
      String password = user.getPassword();
      boolean enabled = user.isEnabled();
  
  
      return new User(email, password, enabled, true, true, true, auth);
  }
  
  public void save(SiteUser user)
  {
      userDao.save(user);
  }
  
  public void updatePass(SiteUser user,String pass){
      user.setPlainPassword(pass);
  }
  
  public String createEmailVerificationToken(SiteUser user)
  {
  
      VerificationToken token = new VerificationToken(UUID.randomUUID().toString(), user, TokenType.REGISTRATION);
      verificationDao.save(token);
      return token.getToken();  
  }
  
  public String createPasswordResetVerificationToken(SiteUser user)
  {
      VerificationToken token = new VerificationToken(UUID.randomUUID().toString(), user, TokenType.PASSWORD_RESET);
      verificationDao.save(token);
      return token.getToken();
  }
  
  public VerificationToken getVerificationToken(String token)
  {
      return verificationDao.findByToken(token);
  }
  
  public void deleteToken(VerificationToken token) {
      verificationDao.delete(token);
  }
  
  public SiteUser get(String email) {
  
      return userDao.findByEmail(email);
  }
  
  public SiteUser get(Long id) {
  
      return userDao.findOne(id);
  }
  </code></pre>
  
  <p>}</p>