Hibernate LockMode
LockMode.NONE :有缓存用缓存,没缓存则从数据库读
LockMode.READ:直接从数据库读,不使用缓存数据
LockMode.WRITE:在insertupdate数据的时候,HIBERNATE内部使用的。
以上3种均为HIBERNATE级别的锁,也就是缓存级别的锁。
下面2种为数据库级别的锁:
LockMode.UPGRADE:相当于SQL语句selectforupdate,被select的数据都被数据库锁住了,不能被其他事务修改。
LockMode. UPGRADE_NOWAIT :是ORACLE数据库特有的select for update nowaitNONE
public static final LockMode NONENo lock required. If an object is requested with this lock mode, a READ lock will be obtained if it is necessary to actually read the state from the database, rather than pull it from a cache.This is the "default" lock mode.
READ
public static final LockMode READA shared lock. Objects in this lock mode were read from the database in the current transaction, rather than being pulled from a cache.
UPGRADE
public static final LockMode UPGRADEDeprecated. instead use PESSIMISTIC_WRITEAn upgrade lock. Objects loaded in this lock mode are materialized using an SQL select ... for update.
UPGRADE_NOWAIT
public static final LockMode UPGRADE_NOWAITAttempt to obtain an upgrade lock, using an Oracle-style select for update nowait. The semantics of this lock mode, once obtained, are the same as UPGRADE.
WRITE
public static final LockMode WRITEA WRITE lock is obtained when an object is updated or inserted. This lock mode is for internal use only and is not a valid mode for load() or lock() (both of which throw exceptions if WRITE is specified).
FORCE
public static final LockMode FORCEDeprecated. instead use PESSIMISTIC_FORCE_INCREMENTSimiliar to
UPGRADE
except that, for versioned entities, it results in a forced version increment.OPTIMISTIC
public static final LockMode OPTIMISTICOptimisticly assume that transaction will not experience contention for entities. The entity version will be verified near the transaction end.
OPTIMISTIC_FORCE_INCREMENT
public static final LockMode OPTIMISTIC_FORCE_INCREMENTOptimisticly assume that transaction will not experience contention for entities. The entity version will be verified and incremented near the transaction end.
PESSIMISTIC_READ
public static final LockMode PESSIMISTIC_READImplemented as PESSIMISTIC_WRITE. TODO: introduce separate support for PESSIMISTIC_READ
PESSIMISTIC_WRITE
public static final LockMode PESSIMISTIC_WRITETransaction will obtain a database lock immediately. TODO: add PESSIMISTIC_WRITE_NOWAIT
PESSIMISTIC_FORCE_INCREMENT
public static final LockMode PESSIMISTIC_FORCE_INCREMENTTransaction will immediately increment the entity version.
相关推荐
82443365 2018-05-23
Johnhao 2014-08-21
wenwst 2019-04-28
lnsoftware 2017-01-23
smilebestSun 2016-03-26
fangjack 2012-02-01
YannZoe 2015-11-27
小源丶同学 2015-09-07
AnyBisks 2019-06-27
GufraYin 2015-03-06
LadyZhong 2012-08-11
hezaichun0 2012-05-22
魄竹 2012-02-09
愚盦 2011-04-08
只有代码的世界 2018-01-23
xiangxiaojun 2015-06-30
hotlinhao 2014-02-08