{"record":{"id":"5e1b4ee8f3bf7974","repo":"hibernate/hibernate-orm","slug":"cannot-unwrap-to-requested-type","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/internal/DataSourceConnectionProvider.java","lineNumber":87,"sourceCode":"\t\tthis.jndiService = jndiService;\n\t}\n\n\t@Override\n\tpublic boolean isUnwrappableAs(@Nonnull Class<?> unwrapType) {\n\t\treturn unwrapType.isAssignableFrom( DataSourceConnectionProvider.class )\n\t\t\t|| unwrapType.isAssignableFrom( DataSource.class);\n\t}\n\n\t@Override\n\tpublic <T> T unwrap(@Nonnull Class<T> unwrapType) {\n\t\tif ( unwrapType.isAssignableFrom( DataSourceConnectionProvider.class ) ) {\n\t\t\treturn unwrapType.cast( this );\n\t\t}\n\t\telse if ( unwrapType.isAssignableFrom( DataSource.class) ) {\n\t\t\treturn unwrapType.cast( getDataSource() );\n\t\t}\n\t\telse {\n\t\t\tthrow new UnknownUnwrapTypeException( unwrapType );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void configure(@Nonnull Map<String, Object> configuration) {\n\t\tif ( dataSource == null ) {\n\t\t\tfinal Object dataSourceSetting = configuration.get( DATASOURCE );\n\t\t\tif ( dataSourceSetting instanceof DataSource instance ) {\n\t\t\t\tdataSource = instance;\n\t\t\t}\n\t\t\telse if ( dataSourceSetting instanceof String jndiName ) {\n\t\t\t\tdataSourceJndiName = jndiName;\n\t\t\t\tif ( jndiService == null ) {\n\t\t\t\t\tthrow new ConnectionProviderConfigurationException( \"Unable to locate JndiService to lookup Datasource\" );\n\t\t\t\t}\n\t\t\t\tdataSource = (DataSource) jndiService.locate( jndiName );\n\t\t\t}\n\t\t\telse {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java#L69-L105","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/internal/DataSourceConnectionProvider.java:87 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Only unwrap the provider to DataSourceConnectionProvider or its supported supertypes/interfaces","Do not request an unrelated type from unwrap()"],"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"}