Manually setting the identifier results in object optimistic locking failure exception

You cannot manually set generated identifier values using the default identifiers. Thanks to a recent improvement Jira, you can however define a custom generator implementation that overrides the allowAssignedIdentifiers(), returning true, to allow for a custom implementation to sporadically use pre-assigned identifier values.

You can also extend from the existing org.hibernate.id.IdentityGenerator to inherit its default behavior when not using existing identifier values. An example of this can be found here.

2 Likes