title: How to update @Entity with Spring Projections?
body: <p>Can I use Spring <code>projections</code> to modify and persist content of existing entities?
  My goal is to update only a specific field. Any other fields of that row in the database should remain untouched. Is that possible with projections?</p>
  <p>Or is a projection always only readonly?</p>
  <pre><code>public void update() {
      PersonProjection p = repository.findByLastname(&quot;Doe&quot;);
      p.setLastname(&quot;test&quot;);
      repository.save(p); //how can I save only that field?
  }
  
  @Entity
  public class Person {
     @Id private long id;
     private String firstname, lastname, age;
  }
  
  interface PersonProjection {
     String getLastname();
     void setLastname(String lastname);
  }
  
  interface PersonRepository extends CrudRepository&lt;Person, Long&gt; {
       PersonProjection findByLastname(String lastname);
  }
  </code></pre>
  <p><a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections" rel="nofollow noreferrer">https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections</a></p>