users@glassfish.java.net

Re: JPA - entityManager.flush()

From: <glassfish_at_javadesktop.org>
Date: Thu, 17 May 2007 09:53:56 PDT

Yes, It's a locking issue. And there are 2 options for you to look at:

1. Use optimistic locking and add a version column to your Task entity. This will result in a rollback of all but one of the transactions (the first one to commit will succeed, the rest will fail).

2. Use pessimistic locking and do "select ... for update" (or similar depending on the particular database). This will put a lock on the row at the time of the query untill commit releases the lock, and the parallel transactions will wait and by the time the lock is released, the flags will be already updated. Now this feature is not there in the spec, so you either need to use provider-specific hints, or a native SQL query.

regards,
-marina
[Message sent by forum member 'mvatkina' (mvatkina)]

http://forums.java.net/jive/thread.jspa?messageID=217683