If I have two threads updating a database in separate transactions with statements that look like
Thread 1
UPDATE people set id='12346' WHERE name='Jeff'
Thread 2
UPDATE people SET name = 'Jeff' WHERE id='12345'
Obviously there is a race here. If Thread 1 changes the id before Thread 2, 12345 will be an invalid ID (assuming no one else is using it).
What I'm wondering is, when using optimistic locking, is this a situation in which an optimistic lock error may be thrown (e.g. a stale record error)? Does the UPDATE/WHERE constitute a read and write or is each UPDATE executed an atomic statement (or does it vary by database)?