title: Spring Data JPA: How to update a model elegantly?
body: <ol>
  <li><p>My Model is like this:</p>
  
  <pre><code>@Entity
  @Table(name = "user")
  public class User {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @Column(name="email")
      private String email;
  
      @Column(name = "weblink")
      private String webLink;
  
      //getter &amp; setter
  }
  </code></pre></li>
  <li><p>we collect form or mobile data via http request, and springmvc will make these data to a Model like user.</p>
  
  <p>for example, I have a request like this:</p>
  
  <p><code>http://localhost:8080/update?id=1919&amp;email=xx@google.com</code> </p></li>
  <li><p>in contoller, the request url and its paramters will be automaticlly trans to a <code>User</code> object.</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, value = "/update0")
  public User update(@ModelAttribute("User") User user){
  
      System.out.println(user.getId());
      System.out.println(user.getEmail());
      System.out.println(user.getWebLink());
  
      return userRepository.save(test);
  }
  </code></pre></li>
  <li><p>if I have a record in mysql which id is 1919, and the columns (id, email, weblik) are all have values.</p>
  
  <p>as you see, the user object which passed by web or mobile have two properties</p>
  
  <p><code>http://localhost:8080/update?id=1919&amp;email=xx@google.com</code></p>
  
  <p>id and email have values and weblink do not have.</p>
  
  <p>So, if i execute <code>save</code> method, the columns email will be updated to <code>xx@google.com</code>, and the weblik field will also be updated to <code>NULL</code>, but I don't want to update this field, I just want to update email field.</p></li>
  <li><p>I have two ways to fix the problem, but all of them are not elegant.</p>
  
  <p>5.1 load user object first and update</p>
  
  <pre><code>User userExist = userRepository.findOne(user.getId());
  userExist.setEmail(user.getEmail());
  
  //or using 
  //BeanUtil.copyProprty(formDto,modle)
  
  userRepository.save();
  </code></pre>
  
  <p>5.2 using <code>@DynamicUpdate</code>, but its not working.</p>
  
  <p>Is there other way to update the User Model and do not do some extra work. </p>
  
  <p>Thanks in advance.</p></li>
  </ol>