1

Is it possible to create a pessimistic lock that last for many user requests?

I'm interested to see if is it possible in Java EE using Hibernate or PHP using Doctrine or Propel. I tried this by using Doctrine 2 but it is not possible, only at database level (per user request).

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
artaxerxe
  • 6,281
  • 21
  • 68
  • 106

1 Answers1

3

It's possible but a lot of (manual) work. All the frameworks for Hibernate and J2EE use filters to begin a sessions as a request is received and commit it when the response is sent.

So what you need to do is to disable this filter for your servlet, create the Hibernate session using the factory, put it into the user's HTTP session and then use that H. session for your work.

Note that there is no safe way to end such a session because the user can simply stop using the browser for a couple of hours.

Something that might be much more useful and stable is "temporary" objects: When the user makes changes, save temporary objects to the database which shadow the the "real" objects. This allows you to save any change immediately. When the user is happy with the result, he can click a button and you can copy the data from the temp objects back to the real ones (with optimistic locking, of course).

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820