Hibernate LockMode
LockMode.NONE:キャッシュ用キャッシュがあり、キャッシュがない場合はデータベースからLockModeを読む.READ:直接データベースから読み、キャッシュデータを使用しないロックモード.WRITE:insert updateデータの場合、HIBERNATE内部で使用されます.以上の3つはいずれもHIBERNATEレベルのロック,すなわちキャッシュレベルのロックである.次の2つはデータベースレベルのロックです:LockMode.UPGRADE:SQL文select for updateに相当し、selectされたデータはデータベースにロックされ、他のトランザクションによって変更できません. LockMode. UPGRADE_NOWAIT:ORACLEデータベース特有のselect for update nowait
NONE
No 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
A shared lock. Objects in this lock mode were read from the database in the current transaction, rather than being pulled from a cache.
UPGRADE
Deprecated.
instead use PESSIMISTIC_WRITE
An upgrade lock. Objects loaded in this lock mode are materialized using an SQL
select ... for update.
UPGRADE_NOWAIT
Attempt 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
A
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
Deprecated.
instead use PESSIMISTIC_FORCE_INCREMENT
Similiar to
UPGRADE except that, for versioned entities, it results in a forced version increment.
OPTIMISTIC
Optimisticly assume that transaction will not experience contention for entities. The entity version will be verified near the transaction end.
OPTIMISTIC_FORCE_INCREMENT
Optimisticly assume that transaction will not experience contention for entities. The entity version will be verified and incremented near the transaction end.
PESSIMISTIC_READ
Implemented as PESSIMISTIC_WRITE. TODO: introduce separate support for PESSIMISTIC_READ
PESSIMISTIC_WRITE
Transaction will obtain a database lock immediately. TODO: add PESSIMISTIC_WRITE_NOWAIT
PESSIMISTIC_FORCE_INCREMENT
Transaction will immediately increment the entity version.
NONE
public static final LockMode NONE
No 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 READ
A 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 UPGRADE
Deprecated.
instead use PESSIMISTIC_WRITE
An upgrade lock. Objects loaded in this lock mode are materialized using an SQL
select ... for update.
UPGRADE_NOWAIT
public static final LockMode UPGRADE_NOWAIT
Attempt 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 WRITE
A
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 FORCE
Deprecated.
instead use PESSIMISTIC_FORCE_INCREMENT
Similiar to
UPGRADE except that, for versioned entities, it results in a forced version increment.
OPTIMISTIC
public static final LockMode OPTIMISTIC
Optimisticly 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_INCREMENT
Optimisticly 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_READ
Implemented as PESSIMISTIC_WRITE. TODO: introduce separate support for PESSIMISTIC_READ
PESSIMISTIC_WRITE
public static final LockMode PESSIMISTIC_WRITE
Transaction will obtain a database lock immediately. TODO: add PESSIMISTIC_WRITE_NOWAIT
PESSIMISTIC_FORCE_INCREMENT
public static final LockMode PESSIMISTIC_FORCE_INCREMENT
Transaction will immediately increment the entity version.