Use eclipselink.pessimistic-lock
to specify if EclipseLink uses pessimistic locking.
Values
Table 4-25 describes this query hint's valid values.
Table 4-25 Valid Values for org.eclipse.persistence.config.PessimisticLock
Value | Description |
---|---|
|
(Default) Do not use pessimistic locking. |
|
EclipseLink issues |
|
EclipseLink issues |
Usage
The primary advantage of using pessimistic locking is that you are assured, once the lock is obtained, of a successful edit. This is desirable in highly concurrent applications in which optimistic locking may cause too many optimistic locking errors.
One drawback of pessimistic locking is that it requires additional database resources, requiring the database transaction and connection to be maintained for the duration of the edit. Pessimistic locking may also cause deadlocks and lead to concurrency issues.
Examples
Example 4-50 shows how to use this hint in a JPA query.
Example 4-50 Using pessimistic-lock in a JPA Query
import org.eclipse.persistence.config.PessimisticLock; import org.eclipse.persistence.config.QueryHints; query.setHint(QueryHints.PESSIMISTIC_LOCK, PessimisticLock.LockNoWait);
Example 4-51 shows how to use this hint with the @QueryHint
annotation.
Example 4-51 Using pessimistic-lock in a @QueryHint Annotation
import org.eclipse.persistence.config.PessimisticLock; import org.eclipse.persistence.config.QueryHints; @QueryHint(name=QueryHints.PESSIMISTIC_LOCK, value=PessimisticLock.LockNoWait);
See Also
For more information, see:
EclipseLink Examples
http://wiki.eclipse.org/EclipseLink/Examples/JPA/PessimisticLocking
"Scaling EclipseLink Applications in Clusters" in Solutions Guide for EclispeLink
"Understanding Queries" in Understanding EclipseLink
"Building Blocks of a EclipseLink Project" in Understanding EclipseLink