title: Spring Data JPA - Why are changes to a returned Entity automatically persisted?
body: <p>I present the question with an example.</p>
  
  <p>Assert that we have a Repository such as the below:</p>
  
  <pre><code>public interface ExampleObjectRepository extends CrudRepository&lt;ExampleObject, Long&gt; {
  
  }
  </code></pre>
  
  <p>By extending the <code>JpaRepository</code> interface, the <code>ExampleObject</code> repository inherits the following method:</p>
  
  <pre><code>T findOne(ID id);
  </code></pre>
  
  <p>Now, I have observed that, if I receive a reference to an ExampleObject after a call to this method, any manipulations that I make to this method are automatically saved to the database, for example:</p>
  
  <pre><code>ExampleObject pointInCase = exampleObjectRepository.findOne(1L);
  pointInCase.setName("Something else");
  </code></pre>
  
  <p>Reading around the subject, I understand this this signfies that <code>ExampleObject</code> instance is <code>not detached</code>.</p>
  
  <p>This goes against my expectations. I would have expected that I would need to use the save method inherited from <code>CrudRepository</code> in order to save the changes:</p>
  
  <pre><code>T save(T entity);
  </code></pre>
  
  <p>Would anyone be kind enough to confirm that objects returned from a Spring Data JPA Repository remain attached as standard, and explain how to use the API to mark a method in the repository such that it only returns detached references?</p>
  
  <p>I imagine that changing the entity's state may also change its definition when it is used with said <code>save(T entity)</code> method, so I would also appreciate an understanding of how identity for updates are handled.</p>