no_ejb wrote:
Again this is pessmistic lock and allows dirty read and with no database lock involved so it works well in HTTP environment. This is the only way to avoid heavy user change get lost. On the other hand if the changes are minor, db optimistic lock works well.
Are you using some sort of expire time for the lock also? (i.e. two locking related fields per entity). Are you only locking the top of the object graph, assuming nobody else messes with the lower parts. OK, you can't force other software to respect your lock anyway.
Like I said, I have been experimenting with a static BeanMerger class that used in conjunction with a timestamp can take any two JavaBean standard-respecting object graphs and merge (overwrite) the changes using reflection, returning a data structure saying what has been changed. That way, the save scenario could (hopefully) be as follows:
t=5 user B writes back object X (fails)
t=6 system check for timestamp match
t=7 if match => write back object X
t=8 if no match check with user if do a clen reload graph from disk or
load&merge. User can review what has changed, if OK
t=9 user B writes back object X
Of course I must still check on the atomicity of the save action.