title: Optimistic locking not throwing exception when manually setting version field
body: <p>I have a Spring Boot 1.3.M1 web application using Spring Data JPA. For optimistic locking, I am doing the following:</p>
  
  <ol>
  <li>Annotate the version column in the entity: <code>@Version private long version;</code>. I confirmed, by looking at the database table, that this field is incrementing properly.</li>
  <li>When a user requests an entity for editing, sending the <code>version</code> field as well.</li>
  <li>When the user presses submit after editing, receiving the <code>version</code> field as a hidden field or something.</li>
  <li><p>Server side, fetching a fresh copy of the entity, and then updating the desired fields, along with the <code>version</code> field. Like this:</p>
  
  <pre><code>User user = userRepository.findOne(id);
  user.setName(updatedUser.getName());
  user.setVersion(updatedUser.getVersion());
  userRepository.save(user);
  </code></pre></li>
  </ol>
  
  <p>I was expecting this to throw exception when the versions wouldn't match. But it doesn't. Googling, I found some posts saying that we can't set the <code>@Vesion</code> property of an attached entity, like I'm doing in the third statement above.</p>
  
  <p>So, I am guessing that I'll have to manually check for the version mismatch and throw the exception myself. Would that be the correct way, or I am missing something?</p>