I see two classes for locking in hibernate -
LockOptions
LockMode
What is the difference between the two? When to use each?
最近在搞数据库的并发问题,开发环境用到了spring+hibernate的架构,数据库是mysql,
在用到悲观锁的时候发现用query.setLockMode("u", LockMode.PESSIMISTIC_WRITE);的方式无法锁定表,
打印的sql语句中也没有for update的字段。
后来换成query.setLockOptions(LockOptions.UPGRADE);才成功锁定表。
在百度上查了好久都没有查到原因,后来在一个英文网站找到了答案,原文如下
2
1
|
I see two classes for locking in hibernate -
What is the difference between the two? When to use each? |
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
0
|
I don't have a definite answer but for MySQL the only way to generate a
| ||||||||
|