1. 程式人生 > >關於hibernate悲觀鎖設定方法setLockMode無效而setLockOptions有效的解答

關於hibernate悲觀鎖設定方法setLockMode無效而setLockOptions有效的解答

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


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);
 – Reddy Sep 21 '10 at 16:21
Yes, most probably it's the bug you mention. Thanks. – cherouvim Sep 21 '10 at 18:03

看來這個似乎是mysql的一個bug?搞不太明白。