{"record":{"id":"bfda3c5b6a284739","repo":"hibernate/hibernate-orm","slug":"cannot-make-an-entity-of-immutable-type-modif","errorCode":null,"errorMessage":"Cannot make an entity of immutable type '{}' modifiable","messagePattern":"Cannot make an entity of immutable type '(.+?)' modifiable","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java","lineNumber":447,"sourceCode":"\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 );\n\t\t\t\tloadedState = persister.getValues( entity );\n\t\t\t\tfinal var context = getPersistenceContext();\n\t\t\t\tTypeHelper.deepCopy(\n\t\t\t\t\t\tloadedState,\n\t\t\t\t\t\tpersister.getPropertyTypes(),\n\t\t\t\t\t\tpersister.getPropertyCheckability(),\n\t\t\t\t\t\tloadedState,\n\t\t\t\t\t\tcontext.getSession()\n\t\t\t\t);\n\t\t\t\tif ( persister.hasNaturalIdentifier() ) {\n\t\t\t\t\tcontext.getNaturalIdResolutions().manageLocalResolution(\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tpersister.getNaturalIdMapping().extractNaturalIdFromEntityState( loadedState ),\n\t\t\t\t\t\t\tpersister,","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java#L429-L465","documentation":"Error \"Cannot make an entity of immutable type '{}' modifiable\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java:447 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not call setReadOnly(false) or make modifiable on an @Immutable entity","Remove the @Immutable annotation if the entity must be mutable"],"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"}