Have you ever wondered why Hibernate sometimes executes a select statement before the insert?
This happens when the Id is assigned by the program and not generated by Hibernate and @Version is not used. See Person
To avoid this select statement there are two solutions:
-
Either use @GeneratedValue as in PersonWithGeneratedId
-
or if you want to assign the Id you must use @Version as in PersonWithVersion