indent | ||||
---|---|---|---|---|
| ||||
{color:green}Have any suggestion on how improve this wiki? Please give us your feedback at [mailto:csf-support@mit.edu]{color} |
Panel | ||||
---|---|---|---|---|
Quick Links to:
|
Panel | ||
---|---|---|
About this Pageindent | | 1 | 1
Panel | ||
---|---|---|
Example Situationindent | | 1 | 1
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 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. It probably makes sense then to always use a hibernate get for retrieval. This outline shows the issue - 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 ReadingSome useful information is available here: | |||
Panel | |||
Further Readingindent | | 1 | 1 | Some useful information is available here: * [Hibernate (3.3) Documentation|http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/objectstate.html] * ["Hibernate in Action" PDF|https://web.mit.edu/sturner/www/secure/HibernateInAction.pdf] * ["Java Persistence with Hibernate" PDF|https://web.mit.edu/sturner/www/secure/JavaPersistenceWithHibernate.pdf]