3

I see two classes for locking in hibernate -

  1. LockOptions
  2. LockMode

What is the difference between the two? When to use each?

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
Reddy
  • 8,737
  • 11
  • 55
  • 73

2 Answers2

1

Referring to the Session javadoc http://docs.jboss.org/hibernate/orm/4.2/javadocs/, LockMode parameter should be replaced with LockOptions.

Here is the excerpt from the javadoc.

@Deprecated Object load(String entityName, Serializable id, LockMode lockMode) Deprecated. LockMode parameter should be replaced with LockOptions Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.

Parameters:

entityName - a persistent class

id - a valid identifier of an existing persistent instance of the class

lockMode - the lock level

Returns:

the persistent instance or proxy

Chandra Divi
  • 419
  • 4
  • 2
0

I don't have a definite answer but for MySQL the only way to generate a for update sql statement was:

query.setLockOptions(LockOptions.UPGRADE);
cherouvim
  • 31,725
  • 15
  • 104
  • 153
  • Are you sure? Or are you talking about this bug? http://stackoverflow.com/questions/3028478/how-to-specify-pessimistic-lock-with-criteria-api – Reddy Sep 21 '10 at 16:21
  • Yes, most probably it's the bug you mention. Thanks. – cherouvim Sep 21 '10 at 18:03