JPA Doesn't Call Persist But Merge Operation On New Entities
When working with JPA I prefer generating the primary key on the application and not in the database (check out this post from James Brundege ). Additionally, I also prefer optimistic locking and in order to use it you need to specify a @Version field in your Entity. But you need to be careful how to initialize these two fields. In this post I’ll talk about an error when you assign a default value for both fields in JPA which leads the EntityManager to never call persist but the merge operation instead when creating a new entity.