{"record":{"id":"1a6510f8c859e73a","repo":"hibernate/hibernate-orm","slug":"hibernate-cannot-unwrap-getclass-getname","errorCode":null,"errorMessage":"Hibernate cannot unwrap '\" + getClass().getName() + \"' as '\" + type.getName() + \"'","messagePattern":"Hibernate cannot unwrap '\" \\+ getClass\\(\\)\\.getName\\(\\) \\+ \"' as '\" \\+ type\\.getName\\(\\) \\+ \"'","errorType":"exception","errorClass":"PersistenceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java","lineNumber":1889,"sourceCode":"\t\treturn CacheLoadHelper.loadFromSecondLevelCache( this, instanceToLoad, lockMode, persister, entityKey );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic TransactionCompletionCallbacksImplementor getTransactionCompletionCallbacksImplementor() {\n\t\treturn transactionCompletionCallbacks.forSharing();\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <T> T unwrap(@Nonnull Class<T> type) {\n\t\tcheckOpen();\n\n\t\tif ( type.isInstance( this ) ) {\n\t\t\treturn type.cast( this );\n\t\t}\n\n\t\tthrow new PersistenceException( \"Hibernate cannot unwrap '\" + getClass().getName()\n\t\t\t\t\t\t\t\t\t\t+ \"' as '\" + type.getName() + \"'\" );\n\t}\n\n}\n","sourceCodeStart":1871,"sourceCodeEnd":1894,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java#L1871-L1894","documentation":"Error \"Hibernate cannot unwrap '\" + getClass().getName() + \"' as '\" + type.getName() + \"'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:1889 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Unwrap only to interfaces supported by StatelessSession (e.g. StatelessSession itself, SharedSessionContractImplementor); otherwise adapt manually."],"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"}