I'm having a complete brain lapse today and am looking for a little clarification on how to accomplish locking in our app. I believe I understand how optimistic locking works, but I'm still missing something on how to use it in a web environment.
From the docs:
Code:
// foo is an instance loaded by a previous Session
foo.setProperty("bar");
session = factory.openSession();
session.saveOrUpdate(foo);
session.flush();
session.connection().commit();
session.close();
When the web page is requested, I load foo and send it to the page for rendering. The user then changes a couple of values and submits the form. By the paradigm described above, I have to modify the same
instance of foo in order to ensure it has not been modified by another user. My real question is...how do I hold on to foo once the page has been loaded so I can modify it after user think time? Do I put it into the HTTP session? The other option is to reload the object and do a manual version check, but I'd much rather let Hibernate take care of it for me. Any suggestions?