There are a couple of solutions to this:
1) The finder takes a 'update-intent', basically exclusive, lock in the
database.
   A fix that does this has been vetoed by Bill Burke, although you can
implement it
   yourself with BMP or by using database-specific <declared-sql/> for
the finder.

2) Leave the finder running with a Read-Committed isolation level and
have the entity
   implementation deal with the phantom case by checking that the
current values match 
   the values that caused the object to be returned by the finder. In
other words,
   check that foo is still null when you try and set it to bar and if
not throw an 
   exception indicating concurrent modification.

Jeremy

/*************************
 * Jeremy Boynes
 * Partner
 * Core Developers Network
 *************************/ 

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Ittay Dror
> Sent: Thursday, July 10, 2003 12:39 PM
> To: JBoss-User
> Subject: [JBoss-user] transactions & synchronizations
> 
> 
> Say I have the following case:
> 
> 1. a session bean queries with ejb ql for entity beans with a 
> specific property value. name the property 'foo' and the 
> value 'bar'. It queries the entities whose foo property is 
> null, selects the first and sets its value to bar
> 
> 2. two threads call the session bean:
>    a. thread-a does the query, gets an entity, changes its 
> value to bar.
>    b. in the meanwhile, thread-b also does the same and 
> therefore gets the same entity bean.
> 
> 3. say the session bean's method is synchronized (inside of 
> it, there is a synchroniztion). this doesn't help, since 
> jboss only commits the changes once the method returns, so 
> when thread-a steps out of the synchronization block, 
> thread-b steps in, before jboss commits the changes.
> 
> what is the solution to this? transactions? (i've tried 
> RequiresNew, with no luck) or syncrhonizing before the call 
> to the session bean (rather than in it)? this means every 
> client needs to add this synchronization..
> 
> please help,
> thank you,
> ittay
> -- 
> =======================================
> Ittay Dror ([EMAIL PROTECTED])
> User Space, R&D
> Qlusters Inc.
> Tel: +972-3-6081956 Fax: +972-3-6081841
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email sponsored by: Parasoft
> Error proof Web apps, automate testing & more.
> Download & eval WebKing and get a free book. 
> www.parasoft.com/bulletproofapps1 
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED] 
> https://lists.sourceforge.net/lists/listinfo/j> boss-user
> 



-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to