title: JPA / Hibernate / MS SQL Server not returning generated id value
body: <p>I am using Hibernate entity manager 3.5.1-Final with MS SQL Server 2005 and trying to persist multiple new entities. My entity is annotationally configured thus:</p>
  
  <pre><code>@Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private int id;
  </code></pre>
  
  <p>After calling </p>
  
  <pre><code>entityManager.persist(newEntity)
  </code></pre>
  
  <p>I do not see the generatedId set, it remains as 0. This causes the following exception when persisting the next new entity:</p>
  
  <pre><code>org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [x.y.z.MyEntity#0]
  </code></pre>
  
  <p>I can get round this by evicting the recently persisted entity from the cache before I persist the next entity, but this is not ideal. What do I need to do to update the object correctly after insert?</p>