...
Panel | ||||
---|---|---|---|---|
Quick Links to:
|
Panel | |||
---|---|---|---|
About this Pageindent | | 1 | 1 |
Panel |
---|
Example SituationTo set the scene, here's a typical situation in our web applications:
Obviously this isn't good; when Dave David finally submits changes, we need the app to detect that someone else has changed the data, and to handle the situation appropriately. Two aspects to doing this are:
We'll take these in reverse order: |
Panel | |||
---|---|---|---|
Handling a Concurrent Update Situationindent | | 1 | 1 |
Panel | |||
---|---|---|---|
Detectionindent | | 1 | 1 |
Panel | ||||||
---|---|---|---|---|---|---|
Chosen Solutionindent | | 1 | 1
Code Block |
---|
} svn+ssh://svn.mit.edu/csf-playground/web-concurrency {code} |
Also
there
is
a
non-web
project
that
uses
a
unit
test
\[TestConcurrency.testConcurrentUpdate()
\]
to
illustrate
the
concurrent
update
situation:
Code Block |
---|
} svn+ssh://svn.mit.edu/csf-playground/hibernate-concurrency {code} |
NOTE:
if
the
web
page
displays
multiple
objects
that
can
be
updated,
the
version
numbers
of
all
the
objects
must
be
included
in
the
JSP,
and
must
all
be
applied
to
the
relevant
entity
objects
when
the
form
data
is
posted.
Panel | ||
---|---|---|
IMPORTANT: Load vs GetThere is a difference between Hibernate's load and get methods for retrieving data that is could be important in checking for concurrent updates:
The reason this is important for concurrent update checking is that a proxy object generated by a load will not contain the version information we need. Our scheme depends on the version being loaded at the start of a It probably makes sense then to always use a hibernate get for retrieval. This outline shows the issue - with two sessions working with an object with the same identifier. Initial version for object in DB is 10.
We actually want session 1's commit to fail with an optimistic lock exception, but it will succeed here. Using "get" instead of "load" works around the problem, because get will immediately issue a select, and the version numbers will be loaded at the correct times for the optimistic lock checking. We actually want session 1's commit to fail with an optimistic lock exception, but it will succeed here. Using "get" instead of "load" works around the problem, because get will immediately issue a select, and the version numbers will be loaded at the correct times for the optimistic lock checking. |
Panel | ||
---|---|---|
Further Readingindent | | 1 |