Package org.hibernate
Enum LockMode
- java.lang.Object
-
- java.lang.Enum<LockMode>
-
- org.hibernate.LockMode
-
- All Implemented Interfaces:
Serializable
,Comparable<LockMode>
public enum LockMode extends Enum<LockMode>
Instances represent a lock mode for a row of a relational database table. It is not intended that users spend much time worrying about locking since Hibernate usually obtains exactly the right lock level automatically. Some "advanced" users may wish to explicitly specify lock levels.- See Also:
Session.lock(Object, LockMode)
-
-
Enum Constant Summary
Enum Constants Enum Constant Description NONE
No lock required.OPTIMISTIC
Optimistically assume that transaction will not experience contention for entities.OPTIMISTIC_FORCE_INCREMENT
Optimistically assume that transaction will not experience contention for entities.PESSIMISTIC_FORCE_INCREMENT
Transaction will immediately increment the entity version.PESSIMISTIC_READ
Implemented as PESSIMISTIC_WRITE.PESSIMISTIC_WRITE
Transaction will obtain a database lock immediately.READ
A shared lock.UPGRADE_NOWAIT
Attempt to obtain an upgrade lock, using an Oracle-styleselect for update nowait
.UPGRADE_SKIPLOCKED
Attempt to obtain an upgrade lock, using an Oracle-styleselect for update skip locked
.WRITE
AWRITE
lock is obtained when an object is updated or inserted.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LockMode
fromExternalForm(String externalForm)
static LockMode
fromJpaLockMode(LockModeType lockMode)
boolean
greaterThan(LockMode mode)
Check if this lock mode is more restrictive than the given lock mode.boolean
lessThan(LockMode mode)
Check if this lock mode is less restrictive than the given lock mode.String
toExternalForm()
LockModeType
toJpaLockMode()
static LockModeType
toJpaLockMode(LockMode lockMode)
static LockMode
valueOf(String name)
Returns the enum constant of this type with the specified name.static LockMode[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
NONE
public static final LockMode NONE
No lock required. If an object is requested with this lock mode, aREAD
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.
-
OPTIMISTIC
public static final LockMode OPTIMISTIC
Optimistically 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
Optimistically assume that transaction will not experience contention for entities. The entity version will be verified and incremented near the transaction end.
-
WRITE
public static final LockMode WRITE
AWRITE
lock is obtained when an object is updated or inserted. This lock mode is for internal use only and is not a valid mode forload()
orlock()
, both of which throw exceptions ifWRITE
is specified.
-
UPGRADE_NOWAIT
public static final LockMode UPGRADE_NOWAIT
Attempt to obtain an upgrade lock, using an Oracle-styleselect for update nowait
. The semantics of this lock mode, once obtained, are the same asPESSIMISTIC_WRITE
.
-
UPGRADE_SKIPLOCKED
public static final LockMode UPGRADE_SKIPLOCKED
Attempt to obtain an upgrade lock, using an Oracle-styleselect for update skip locked
. The semantics of this lock mode, once obtained, are the same asPESSIMISTIC_WRITE
.
-
PESSIMISTIC_READ
public static final LockMode PESSIMISTIC_READ
Implemented as PESSIMISTIC_WRITE.
-
PESSIMISTIC_WRITE
public static final LockMode PESSIMISTIC_WRITE
Transaction will obtain a database lock immediately.
-
PESSIMISTIC_FORCE_INCREMENT
public static final LockMode PESSIMISTIC_FORCE_INCREMENT
Transaction will immediately increment the entity version.
-
-
Method Detail
-
values
public static LockMode[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (LockMode c : LockMode.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static LockMode valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
fromJpaLockMode
public static LockMode fromJpaLockMode(LockModeType lockMode)
-
toJpaLockMode
public static LockModeType toJpaLockMode(LockMode lockMode)
-
toJpaLockMode
public LockModeType toJpaLockMode()
-
greaterThan
public boolean greaterThan(LockMode mode)
Check if this lock mode is more restrictive than the given lock mode.- Parameters:
mode
- LockMode to check- Returns:
- true if this lock mode is more restrictive than given lock mode
-
lessThan
public boolean lessThan(LockMode mode)
Check if this lock mode is less restrictive than the given lock mode.- Parameters:
mode
- LockMode to check- Returns:
- true if this lock mode is less restrictive than given lock mode
-
toExternalForm
public String toExternalForm()
-
-