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.
Session.lock(Object, LockMode)
Enum Constant and Description |
---|
FORCE
Deprecated.
instead use PESSIMISTIC_FORCE_INCREMENT
|
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
Deprecated.
instead use PESSIMISTIC_WRITE
|
UPGRADE_NOWAIT
Attempt to obtain an upgrade lock, using an Oracle-style
<tt>select for update nowait</tt>.
|
UPGRADE_SKIPLOCKED
Attempt to obtain an upgrade lock, using an Oracle-style
<tt>select for update skip locked</tt>.
|
WRITE
A <tt>WRITE</tt> lock is obtained when an object is updated
or inserted.
|
Modifier and Type | Method and Description |
---|---|
static LockMode |
fromExternalForm(String externalForm) |
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() |
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.
|
public static final LockMode NONE
No lock required. If an object is requested with this lock mode, a <tt>READ</tt> lock will be obtained if it is necessary to actually read the state from the database, rather than pull it from a cache.<br> <br> This is the "default" lock mode.
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.
@Deprecated public static final LockMode UPGRADE
An upgrade lock. Objects loaded in this lock mode are materialized using an SQL <tt>select … for update</tt>.
public static final LockMode UPGRADE_NOWAIT
Attempt to obtain an upgrade lock, using an Oracle-style <tt>select for update nowait</tt>. The semantics of this lock mode, once obtained, are the same as <tt>UPGRADE</tt>.
public static final LockMode UPGRADE_SKIPLOCKED
Attempt to obtain an upgrade lock, using an Oracle-style <tt>select for update skip locked</tt>. The semantics of this lock mode, once obtained, are the same as <tt>UPGRADE</tt>.
public static final LockMode WRITE
A <tt>WRITE</tt> 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 <tt>load()</tt> or <tt>lock()</tt> (both of which throw exceptions if WRITE is specified).
@Deprecated public static final LockMode FORCE
Similar to UPGRADE
except that, for versioned entities,
it results in a forced version increment.
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.
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.
public static final LockMode PESSIMISTIC_READ
Implemented as PESSIMISTIC_WRITE. TODO: introduce separate support for PESSIMISTIC_READ
public static final LockMode PESSIMISTIC_WRITE
Transaction will obtain a database lock immediately. TODO: add PESSIMISTIC_WRITE_NOWAIT
public static final LockMode PESSIMISTIC_FORCE_INCREMENT
Transaction will immediately increment the entity version.
public static LockMode[] values()
for (LockMode c : LockMode.values()) System.out.println(c);
public static LockMode valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic boolean greaterThan(LockMode mode)
Check if this lock mode is more restrictive than the given lock mode.
mode
- LockMode to checkpublic boolean lessThan(LockMode mode)
Check if this lock mode is less restrictive than the given lock mode.
mode
- LockMode to checkpublic String toExternalForm()
Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.