uCosminexus Application Server, Common Container Functionality Guide
The pessimistic lock is the method of exclusively locking the target records when multiple transactions update the same record on the database. If a transaction sets a pessimistic lock for a particular record, another transaction cannot reference or update that record (however, in Oracle, the record can be referenced). A pessimistic lock is only available when JPQL is used.
If you use a pessimistic lock, until the transaction that obtained the lock terminates, the lock awaits release. Therefore, though the concurrent executions are not more than the optimistic lock, you can prevent the transaction commit errors that occur in the optimistic lock.
Query query = manager.createQuery("SELECT emp FROM Employee AS emp");
query.setHint("cosminexus.jpa.pessimistic-lock","Lock");
|
@NamedQuery(
name="employee_list",
query="SELECT emp FROM Employee AS emp",
hints={ @QueryHint(name="cosminexus.jpa.pessimistic-lock", value="Lock") }
)
@Entity
public class Employee{
...
}
|
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.