Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/PessimisticLocking"

(No difference)

Revision as of 09:06, 17 October 2007

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.jpa.config.EclipseLinkQueryHints
  • org.eclipse.persistence.jpa.config.PessimisticLock

Via Annotations

@Entity
@Table(name="JPA_EMPLOYEE")
@NamedQuery(
  name="findEmployeeByPK",
  query="SELECT OBJECT(employee) FROM Employee employee WHERE employee.id = :id"),
  hints={
    @QueryHint(
      name=EclipseLinkQueryHints.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>

Copyright © Eclipse Foundation, Inc. All Rights Reserved.