Is optimistic locking supposed to catch concurrent update issues?
By concurrent update, I mean that two different users both attempt to update an object with the same version number. For example, if there is a Person domain class, and Person with id = 1, and version = 0, has name = Jack, and two different users both attempt to update the name on version 0, I would expect only one of the user to succeed and change the version to 1. I would expect the second user to get a Hibernate staleStateException or something similar. But that's not what happens.
Here's my use case:
Grails 3.1.5 grails generate-app person grails create-domain-class Person Edit Person.groovy to include String name grails generate-all person.Person gradle bootRun
Use two different browsers to access the app, such as Chrome and Firefox, to ensure that the two browsers are in different sessions. Create a Person in one of them and then open that same person (version 0) for editing in both browsers. Both browsers should now be editing version 0 of person. Save a name change in one browser, this works and changes the persisted version of the object to 1, but the second browser is still editing version 0. Now save the changes in the second browser, this also works. Despite the fact that the second browser just saved changes to a now stale object (version 0) no StaleObject or StaleStateException is thrown. Is this the correct behavior?