{"record":{"id":"01cea3e052899fe7","repo":"hibernate/hibernate-orm","slug":"invalid-lock-mode-lockmode-passed-to-lock","errorCode":null,"errorMessage":"Invalid lock mode '${lockMode}' passed to 'lock()'","messagePattern":"Invalid lock mode '(.+?)' passed to 'lock\\(\\)'","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLockEventListener.java","lineNumber":41,"sourceCode":"public class DefaultLockEventListener implements LockEventListener {\n\n\t/**\n\t * Handle the given lock event.\n\t *\n\t * @param event The lock event to be handled.\n\t */\n\t@Override\n\tpublic void onLock(@Nonnull LockEvent event) {\n\n\t\tfinal Object instance = event.getObject();\n\t\t//noinspection ConstantValue\n\t\tif ( instance == null ) {\n\t\t\tthrow new NullPointerException( \"Attempted to lock null\" );\n\t\t}\n\n\t\tfinal var lockMode = event.getLockMode();\n\t\tif ( lockMode == LockMode.WRITE || lockMode == LockMode.UPGRADE_SKIPLOCKED ) {\n\t\t\tthrow new IllegalArgumentException( \"Invalid lock mode '\" + lockMode + \"' passed to 'lock()'\" );\n\t\t}\n\n\t\tfinal var source = event.getSession();\n\t\tfinal Object entity = forceInitialize( instance, source );\n\t\t//TODO: if instance was an uninitialized proxy, this is inefficient,\n\t\t//      resulting in two SQL selects\n\n\t\tfinal var entry = source.getPersistenceContextInternal().getEntry( entity );\n\t\tif ( entry == null && instance == entity ) {\n\t\t\tthrow new DetachedObjectException( \"Given entity is not associated with the persistence context\" );\n\t\t}\n\t\tassert entry != null;\n\n\t\tupgradeLock( entity, entry, event.getLockOptions(), source );\n\t}\n}\n","sourceCodeStart":23,"sourceCodeEnd":58,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLockEventListener.java#L23-L58","documentation":"Error \"Invalid lock mode '${lockMode}' passed to 'lock()'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when an unsupported LockMode is supplied for the attempted lock operation.","commonSituations":"Typical situations: passing LockMode.WRITE where it is not permitted; a lock mode computed from user input without validation.","solutions":["Pass a valid LockMode value (e.g. NONE, READ, PESSIMISTIC_READ, PESSIMISTIC_WRITE) to lock().","Verify the LockMode comes from the org.hibernate.LockMode enum rather than an arbitrary string."],"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"}