title: JPA: update only specific fields
body: <p>Is there a way for updating <strong>only some fields</strong> of an entity object using the method <code>save</code> from <strong>Spring Data JPA</strong>?</p>
  
  <p>For example I have a JPA entity like this:</p>
  
  <pre><code>@Entity
  public class User {
  
    @Id
    private Long id;
  
    @NotNull
    private String login;
  
    @Id
    private String name;
  
    // getter / setter
    // ...
  }
  </code></pre>
  
  <p>With its CRUD repo:</p>
  
  <pre><code>public interface UserRepository extends CrudRepository&lt;User, Long&gt; { }
  </code></pre>
  
  <p>In <strong>Spring MVC</strong> I have a controller that get an <code>User</code> object for update it: </p>
  
  <pre><code>@RequestMapping(value = "/rest/user", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
  @ResponseBody
  public ResponseEntity&lt;?&gt; updateUser(@RequestBody User user) {
  
     // Assuming that user have its id and it is already stored in the database,
     // and user.login is null since I don't want to change it,
     // while user.name have the new value
  
     // I would update only its name while the login value should keep the value 
     // in the database
     userRepository.save(user);
  
     // ...
  }
  </code></pre>
  
  <p>I know that I could load the user using <code>findOne</code>, then change its name and update it using <code>save</code>... But if I have 100 fields and I want to update 50 of them it could be very annoying change each value.. </p>
  
  <p>Is there no way to tell something like "<strong>skip all null values when save the object</strong>"?</p>