We have a legacy db schema. To isolate our changes from actual tables we created a set of VIEWs. Then we map hibernate to VIEWs, and everything works fine, except one subtle concurrency scenario: "A deletes, B updates". We use optimistic concurrency with <version> field.
I.e.:
CREATE VIEW V_FOO AS select * from T_FOO WHERE DELETED != 'Y'
User A: loads record R with version 1
User B: loads record R with version 1
User A: sets DELETED to 'Y', commit (this increments R version to 2)
VIEW: makes R disappear, but the row is still in T_FOO of course
User B: attempts to merge R, and -- a bug? -- row gets updated!
Note: when Hibernate was mapped to actual table, not view, attempt to update the row was raising an exception.
Presumably Hibernate cannot find R in the view, and decides that null version is okay. I expect Hibernate to throw some kind of exception at this point.
Am I wrong in my expectations?
|