I have a java project that runs on a webserver. I always hit this exception.
I read some documentation, and found that pessimistic locking (or optimistic, but I read
Don't set an Id to the object you are saving as the Id will be autogenerated
Id