{"record":{"id":"20cdc3f2e8174c50","repo":"hibernate/hibernate-orm","slug":"cannot-unwrap-to-requested-type-20cdc3","errorCode":null,"errorMessage":"Cannot unwrap to requested type [{}]","messagePattern":"Cannot unwrap to requested type \\[(.+?)\\]","errorType":"exception","errorClass":"UnknownUnwrapTypeException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/AbstractDataSourceBasedMultiTenantConnectionProviderImpl.java","lineNumber":64,"sourceCode":"\t\treturn true;\n\t}\n\n\t@Override\n\tpublic boolean isUnwrappableAs(@Nonnull Class<?> unwrapType) {\n\t\treturn unwrapType.isInstance( this )\n\t\t\t|| unwrapType.isAssignableFrom( DataSource.class );\n\t}\n\n\t@Override\n\tpublic <X> X unwrap(@Nonnull Class<X> unwrapType) {\n\t\tif ( unwrapType.isInstance( this ) ) {\n\t\t\treturn unwrapType.cast( this );\n\t\t}\n\t\telse if ( unwrapType.isAssignableFrom( DataSource.class ) ) {\n\t\t\treturn unwrapType.cast( selectAnyDataSource() );\n\t\t}\n\t\telse {\n\t\t\tthrow new UnknownUnwrapTypeException( unwrapType );\n\t\t}\n\t}\n}\n","sourceCodeStart":46,"sourceCodeEnd":68,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/AbstractDataSourceBasedMultiTenantConnectionProviderImpl.java#L46-L68","documentation":"Error \"Cannot unwrap to requested type [{}]\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/AbstractDataSourceBasedMultiTenantConnectionProviderImpl.java:64 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only unwrap to types implemented by the abstract multi-tenant provider","Avoid unwrap() to unrelated types"],"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"}