Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "EclipseLink/Examples/JPA/PessimisticLocking"
< EclipseLink | Examples | JPA
m (linked to elug) |
|||
Line 2: | Line 2: | ||
See: | See: | ||
− | * org.eclipse.persistence | + | * org.eclipse.persistence.config.QueryHints |
− | * org.eclipse.persistence | + | * org.eclipse.persistence.config.PessimisticLock |
* [[Configuring_a_Descriptor_%28ELUG%29#Configuring_Locking_Policy|Configuring a Locking Policy]] in the ''EclipseLink User's Guide'' | * [[Configuring_a_Descriptor_%28ELUG%29#Configuring_Locking_Policy|Configuring a Locking Policy]] in the ''EclipseLink User's Guide'' | ||
== Via Annotations == | == Via Annotations == | ||
− | < | + | <source lang="java"> |
@Entity | @Entity | ||
@Table(name="JPA_EMPLOYEE") | @Table(name="JPA_EMPLOYEE") | ||
Line 15: | Line 15: | ||
hints={ | hints={ | ||
@QueryHint( | @QueryHint( | ||
− | name= | + | name=QueryHints.PESSIMISTIC_LOCK, |
value=PessimisticLock.Lock) | value=PessimisticLock.Lock) | ||
} | } | ||
Line 23: | Line 23: | ||
} | } | ||
− | </ | + | </source> |
== Via XML == | == Via XML == | ||
− | < | + | <source lang="xml"> |
<entity name="Employee" class="org.eclipse.testing.Employee" access="PROPERTY"> | <entity name="Employee" class="org.eclipse.testing.Employee" access="PROPERTY"> | ||
... | ... | ||
Line 35: | Line 35: | ||
... | ... | ||
</entity> | </entity> | ||
− | </ | + | </source> |
Revision as of 15:32, 18 June 2008
EclipseLink allows users the option of using pessimistic locking on their queries. This is done through the use of a query hint.
See:
- org.eclipse.persistence.config.QueryHints
- org.eclipse.persistence.config.PessimisticLock
- Configuring a Locking Policy in the EclipseLink User's Guide
Via Annotations
@Entity @Table(name="JPA_EMPLOYEE") @NamedQuery( name="findEmployeeByPK", query="SELECT OBJECT(employee) FROM Employee employee WHERE employee.id = :id"), hints={ @QueryHint( name=QueryHints.PESSIMISTIC_LOCK, value=PessimisticLock.Lock) } ) public class Employee implements Serializable { ... }
Via XML
<entity name="Employee" class="org.eclipse.testing.Employee" access="PROPERTY"> ... <named-query name="findEmployeeByPK"> <query>SELECT OBJECT(employee) FROM Employee employee WHERE employee.id = :id</query> <hint name="eclipselink.pessimistic-lock" value="Lock"> </named-query> ... </entity>