{"record":{"id":"34f39a0cbcc1e05c","repo":"hibernate/hibernate-orm","slug":"persistencecontext-not-available-for-immutable-ent","errorCode":null,"errorMessage":"PersistenceContext not available for immutable entity","messagePattern":"PersistenceContext not available for immutable entity","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java","lineNumber":565,"sourceCode":"\t\t}\n\t}\n\n\t@Override\n\tpublic <T extends EntityEntryExtraState> T getExtraState(Class<T> extraStateType) {\n\t\tif ( next == null ) {\n\t\t\treturn null;\n\t\t}\n\t\telse if ( extraStateType.isInstance( next ) ) {\n\t\t\treturn extraStateType.cast( next );\n\t\t}\n\t\telse {\n\t\t\treturn next.getExtraState( extraStateType );\n\t\t}\n\t}\n\n\tpublic PersistenceContext getPersistenceContext() {\n\t\tif ( persistenceContext == null ) {\n\t\t\tthrow new UnsupportedOperationException( \"PersistenceContext not available for immutable entity\" );\n\t\t}\n\t\treturn persistenceContext;\n\t}\n\n\t/**\n\t * Saves the value for the given enum property.\n\t *\n\t * @param state\n\t *\t\t\tidentifies the value to store\n\t * @param value\n\t *\t\t\tthe value to store; The caller must make sure that it matches\n\t *\t\t\tthe given identifier\n\t */\n\t<E extends Enum<E>> void setCompressedValue(EnumState<E> state, E value) {\n\t\t// reset the bits for the given property to 0\n\t\tcompressedState &= state.getUnsetMask();\n\t\t// store the numeric representation of the enum value at the right offset\n\t\tcompressedState |= ( state.getValue( value ) << state.getOffset() );","sourceCodeStart":547,"sourceCodeEnd":583,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java#L547-L583","documentation":"Error \"PersistenceContext not available for immutable entity\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/EntityEntryImpl.java:565 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not request the persistence context entry for an @Immutable entity that was never loaded into it","Load the entity through the session before accessing its entry"],"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"}