> I've been dusting off my old database book recently, and I've
> run into an interesting problem in transactions -- the Lost Update.
> A lost update occurs in a scenario such as the following. Assume
> two components A and B concurrently perform these operations:
> 1 Component A reads integer X from the database. The database now
> contains X = 0.
> 2 Component B reads integer X from the database. The database now
> contains X = 0.
> 3 Component A adds 10 to its copy of X, and persists it to the
> database. The database now contains X = 10.
>
> 4 Component B adds 10 to its copy of X, and persists it to the
> database. The database now contains X = 10.
> Thus Component A's update has been lost.
There are two possibilities here. Either the components have a cached
copy of X or they do not. If they don't, and if the components always
go to the database, the solution is simple .. an isolation level of
SERIALIZABLE or even READ_COMMITTED will work. (The latter works in
the case of Oracle only because it keeps track of whether the
connection is accessing out of date data. If it is, it'll reject the
second transaction, thus preventing a lost update)
But in this example, the components have a cached copy of X. The
isolation level setting doesn't help because the database has no way
of associating any version information with some private data of
yours. There are two solutions.
1. Force the components never to have the value of X cached and to
use an isolation level of SERIALIZABLE.
2. Put the value X inside a component C and let the EJB server deal
with the concurrency issue. The isolation level doesn't matter, so
you might as well let it be something more lenient and fast, like
READ_COMMITTED.
I prefer solution 2 because the EJB server serializes the transaction
and doesn't require the db to do the same. It is faster because it
doesn't require an isolation level of SERIALIZABLE, which is always
a slow solution.
(Incidentally, if you use #1, the weblogic server allows you to
specify a flag called dbIsShared for container managed beans to
delegate the concurrency to the db)
The main issue here is that the isolation level does not apply to the
components; it applies only to the underlying database connection.
- Sriram
________________________________________________________________________
Principal Engineer BEA/WebLogic, San Francisco www.weblogic.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".