I am using Hibernate 3.5.1-Final entity manager with MS SQL Server 2005 and trying to save several new objects. My object is annotated configured this way:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
After the call
entityManager.persist(newEntity)
I do not see the generated set, it remains equal to 0. This causes the following exception when saving the next new object:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [x.y.z.MyEntity
I can get around this by pushing the recently saved entity out of the cache before I save the next object, but this is not ideal. What do I need to do to correctly update the object after insertion?
source
share