title: Why does Hibernate entity manager perform insert instead of update when dettached entity version property is null?
body: <p>I've noticed that when you have an entity with a @Version property and you try to update a record by manually instantiating the entity, setting its id to an existing id and calling merge(), Hibernate performs an insert instead of an update. I assume this is because the version property is null on the manually instantiated object. Isn't the existence of the identifier adequate for Hibernate to determine that it should perform an update?</p>
  
  <p>Example code:</p>
  
  <p>Assume there is a record with id=1 in the database and MyEntity has a property version with @Version.</p>
  
  <pre><code>MyEntity e = new MyEntity();
  e.setId(1);
  e.setName("some updated value");
  
  entityManager.merge(e);
  </code></pre>
  
  <p>This ends up performing an insert instead of an update.</p>
  
  <p>MyEntity is something like:</p>
  
  <pre><code>@Entity
  public class MyEntity {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Integer id;
  
      @Column("name")
      String name;
  
      @Version
      Integer version;
  
  }
  </code></pre>
  
  <p>If I remove the @Version, it works as expected, the record with id=1 is updated.</p>