{"record":{"id":"ed1c9bcd055426bd","repo":"hibernate/hibernate-orm","slug":"transaction-required-for-lock-mode-lockmode","errorCode":null,"errorMessage":"Transaction required for lock mode \" + lockMode","messagePattern":"Transaction required for lock mode \" \\+ lockMode","errorType":"exception","errorClass":"TransactionRequiredException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java","lineNumber":120,"sourceCode":"\t\t}\n\t\tif ( lockMode == LockMode.READ ) {\n\t\t\treturn LockOptions.READ;\n\t\t}\n\n\t\tfinal var lockOptions = new LockOptions( lockMode );\n\t\tlockOptions.setScope( lockScope != null ? lockScope : PessimisticLockScope.NORMAL );\n\t\tlockOptions.setTimeout( lockTimeout != null ? lockTimeout : Timeouts.WAIT_FOREVER );\n\t\tlockOptions.setFollowOnStrategy( lockFollowOn != null ? lockFollowOn : Locking.FollowOn.ALLOW );\n\t\treturn lockOptions;\n\t}\n\n\tpublic static void checkTransactionNeededForLock(\n\t\t\tSharedSessionContractImplementor session,\n\t\t\tLockMode lockMode) {\n\t\tif ( lockMode != null\n\t\t\t\t&& lockMode.greaterThan( LockMode.NONE )\n\t\t\t\t&& !session.isTransactionInProgress() ) {\n\t\t\tthrow new TransactionRequiredException( \"Transaction required for lock mode \" + lockMode );\n\t\t}\n\t}\n\n\tpublic static <T> void verifyGetMultipleResults(\n\t\t\tList<T> results,\n\t\t\tString entityName,\n\t\t\tList<?> keys,\n\t\t\tFindOption... findOptions) {\n\t\t// how detailed we can get with the error message depends on whether\n\t\t// results are ordered or unordered, defined by the OrderingMode option\n\t\tfinal var orderingMode = determineOrderingMode( findOptions );\n\n\t\tif ( orderingMode == FindMultipleOption.OrderingMode.UNORDERED ) {\n\t\t\tfor ( int i = 0; i < results.size(); i++ ) {\n\t\t\t\tif ( results.get( i ) == null ) {\n\t\t\t\t\tthrow new EntityNotFoundException(\n\t\t\t\t\t\t\t\"No entity of type '%s' existed for one or more of the given ids\"\n\t\t\t\t\t\t\t\t\t.formatted( entityName )","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java#L102-L138","documentation":"Error \"Transaction required for lock mode \" + lockMode\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java:120 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Start a transaction before using a lock mode that requires one (PESSIMISTIC_*/OPTIMISTIC write locks).","Use LockModeType.NONE if no transaction is available."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}