{"record":{"id":"f2cd3341243b2b48","repo":"hibernate/hibernate-orm","slug":"instance-was-not-in-a-valid-state","errorCode":null,"errorMessage":"instance was not in a valid state","messagePattern":"instance was not in a valid state","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java","lineNumber":433,"sourceCode":"\t\treturn persister.isMutable()\n\t\t\t&& status != READ_ONLY\n\t\t\t&& ! ( status == DELETED && previousStatus == READ_ONLY );\n\t}\n\n\t@Override\n\tpublic void forceLocked(Object entity, Object nextVersion) {\n\t\tversion = nextVersion;\n\t\tfinal int versionProperty = persister.getVersionPropertyIndex();\n\t\tloadedState[versionProperty] = version;\n\t\tsetLockMode( PESSIMISTIC_FORCE_INCREMENT );\n\t\tpersister.setValue( entity, versionProperty, nextVersion );\n\t}\n\n\t@Override\n\tpublic boolean isReadOnly() {\n\t\tfinal Status status = getStatus();\n\t\tif ( status != MANAGED && status != READ_ONLY ) {\n\t\t\tthrow new HibernateException(\"instance was not in a valid state\");\n\t\t}\n\t\treturn status == READ_ONLY;\n\t}\n\n\t@Override\n\tpublic boolean setReadOnly(boolean readOnly, Object entity) {\n\t\tfinal boolean changed = readOnly != isReadOnly();\n\t\tif ( changed ) {\n\t\t\tif ( readOnly ) {\n\t\t\t\tsetStatus( READ_ONLY );\n\t\t\t\tloadedState = null;\n\t\t\t}\n\t\t\telse if ( !persister.isMutable() ) {\n\t\t\t\tthrow new IllegalStateException( \"Cannot make an entity of immutable type '\"\n\t\t\t\t\t\t\t\t+ persister.getEntityName() + \"' modifiable\" );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tsetStatus( MANAGED );","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java#L415-L451","documentation":"Error \"instance was not in a valid state\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java:433 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the entity lifecycle state before the operation (do not operate on detached/deleted entries)","Ensure the session is open and the entity entry is in a valid Status for the requested transition"],"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"}