Use eclipselink.pessimistic-lock
to specify if Oracle TopLink uses pessimistic locking.
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. |
|
Oracle TopLink issues |
|
Oracle TopLink issues |
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.
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);
For more information, see:
"Scaling TopLink Applications in Clusters" in Solutions Guide for Oracle TopLink
"Understanding Queries" in Understanding Oracle TopLink
"Building Blocks of a TopLink Project" in Understanding Oracle TopLink