{"record":{"id":"6c711b9c66a967a0","repo":"hibernate/hibernate-orm","slug":"hibernate-cannot-unwrap-getclass-getname-a","errorCode":null,"errorMessage":"Hibernate cannot unwrap '{getClass().getName()}' as '{type.getName()}'","messagePattern":"Hibernate cannot unwrap '(.+?)' as '(.+?)'","errorType":"exception","errorClass":"PersistenceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java","lineNumber":2783,"sourceCode":"\t\tcatch ( RuntimeException e ) {\n\t\t\tthrow getExceptionConverter().convert( e );\n\t\t}\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\tif ( type.isInstance( persistenceContext ) ) {\n\t\t\treturn type.cast( persistenceContext );\n\t\t}\n\n\t\tthrow new PersistenceException(\n\t\t\t\t\"Hibernate cannot unwrap '\" + getClass().getName() + \"' as '\" + type.getName() + \"'\" );\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic Object getDelegate() {\n\t\tcheckOpen();\n\t\treturn this;\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic Collection<?> getManagedEntities() {\n\t\tcheckSessionReentrancy();\n\t\treturn persistenceContext.getEntityHoldersByKey()\n\t\t\t\t.values().stream().map( EntityHolder::getManagedObject )\n\t\t\t\t.toList();\n\t}","sourceCodeStart":2765,"sourceCodeEnd":2801,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java#L2765-L2801","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/SessionImpl.java:2783 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Unwrap only to types supported by Session/SessionImpl (e.g. Session.class, SessionImplementor.class, Connection via doWork).","Cast or adapt manually if the target type is not a supported unwrap interface."],"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"}