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

From Eclipsepedia

Jump to: navigation, search
(Via XML)
(Via Annotations)
Line 11: Line 11:
 
     @QueryHint(
 
     @QueryHint(
 
       name=EclipseLinkQueryHints.PESSIMISTIC_LOCK,  
 
       name=EclipseLinkQueryHints.PESSIMISTIC_LOCK,  
       value=EclipseLinkQueryHints.PESSIMISTIC_LOCK)
+
       value=PessimisticLock.Lock)
 
   }
 
   }
 
)
 
)

Revision as of 16:07, 15 October 2007

EclipseLink allows users the option of using pessimistic locking on their queries. This is done through the use of a query hint.

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="eclipselink.pessimistic-lock">
  </named-query>
  ...
</entity>