hibernate/hibernate-orm · error · TransactionRequiredException
Transaction required for lock mode " + lockMode
Error message
Transaction required for lock mode " + lockMode
What it means
Error "Transaction required for lock mode " + lockMode" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java:120
}
if ( lockMode == LockMode.READ ) {
return LockOptions.READ;
}
final var lockOptions = new LockOptions( lockMode );
lockOptions.setScope( lockScope != null ? lockScope : PessimisticLockScope.NORMAL );
lockOptions.setTimeout( lockTimeout != null ? lockTimeout : Timeouts.WAIT_FOREVER );
lockOptions.setFollowOnStrategy( lockFollowOn != null ? lockFollowOn : Locking.FollowOn.ALLOW );
return lockOptions;
}
public static void checkTransactionNeededForLock(
SharedSessionContractImplementor session,
LockMode lockMode) {
if ( lockMode != null
&& lockMode.greaterThan( LockMode.NONE )
&& !session.isTransactionInProgress() ) {
throw new TransactionRequiredException( "Transaction required for lock mode " + lockMode );
}
}
public static <T> void verifyGetMultipleResults(
List<T> results,
String entityName,
List<?> keys,
FindOption... findOptions) {
// how detailed we can get with the error message depends on whether
// results are ordered or unordered, defined by the OrderingMode option
final var orderingMode = determineOrderingMode( findOptions );
if ( orderingMode == FindMultipleOption.OrderingMode.UNORDERED ) {
for ( int i = 0; i < results.size(); i++ ) {
if ( results.get( i ) == null ) {
throw new EntityNotFoundException(
"No entity of type '%s' existed for one or more of the given ids"
.formatted( entityName )View on GitHub (pinned to fad1729dce)
Solutions
- Start a transaction before using a lock mode that requires one (PESSIMISTIC_*/OPTIMISTIC write locks).
- Use LockModeType.NONE if no transaction is available.
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java:120 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ed1c9bcd055426bd.
Report an issue: GitHub.