title: Check if email already exists in database, but ignore if user is the same
body: <p>I have method which updates the user info. I want to check if email already exists in the database and if this is the case to throw an exception which I handle. So far so good I am checking if there is same email in database, but the problem is that if an existing user tries to update his profile and leaves his email the same the method will find his existing email and return that "email is already in use". How to check if this isn't the same user ? </p>
  
  <pre><code>public User updateUser(UserDTO updateUser) throws IllegalArgumentException {
      System.out.print(updateUser.getId());
      User user = this.userRepository.findOneById(updateUser.getId());
      if (user == null) {
          user = new User();
      }
  
      if (updateUser.getEmail() != null &amp;&amp; !updateUser.getEmail().equals("")) {
          User userCheck = this.userRepository.findOneByEmail(updateUser.getEmail());
          if (userCheck == null) {
              user.setEmail(updateUser.getEmail());
          } else {
              throw new IllegalArgumentException("Email already in use!");
          }
      }
      return this.userRepository.save(user);
  }
  </code></pre>