{"record":{"id":"cac7ecace3ff78a1","repo":"hibernate/hibernate-orm","slug":"hibernate-cannot-unwrap-cache-as-type-getname-cac7ec","errorCode":null,"errorMessage":"Hibernate cannot unwrap Cache as '{type.getName()}'","messagePattern":"Hibernate cannot unwrap Cache as '(.+?)'","errorType":"exception","errorClass":"PersistenceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/cache/internal/EnabledCaching.java","lineNumber":520,"sourceCode":"\t\tgetRegion( regionName ).clear();\n\t\tfinal var queryResultsRegionWithDuplicateName =\n\t\t\t\tqueryResultsRegionsByDuplicateName.get( regionName );\n\t\tif ( queryResultsRegionWithDuplicateName != null ) {\n\t\t\tqueryResultsRegionWithDuplicateName.clear();\n\t\t}\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic <T> T unwrap(@Nonnull Class<T> type) {\n\t\tif ( type.isAssignableFrom( EnabledCaching.class ) ) {\n\t\t\treturn type.cast( this );\n\t\t}\n\t\telse if ( type.isAssignableFrom( RegionFactory.class ) ) {\n\t\t\treturn type.cast( regionFactory );\n\t\t}\n\t\telse {\n\t\t\tthrow new PersistenceException( \"Hibernate cannot unwrap Cache as '\" + type.getName() + \"'\" );\n\t\t}\n\t}\n\n\t@Override\n\tpublic void close() {\n\t\tfor ( var region : regionsByName.values() ) {\n\t\t\tregion.destroy();\n\t\t}\n\t\tfor ( var region : queryResultsRegionsByDuplicateName.values() ) {\n\t\t\tregion.destroy();\n\t\t}\n\t}\n\n\n\t// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// JPA-defined methods\n\n\t@Override","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/cache/internal/EnabledCaching.java#L502-L538","documentation":"Error \"Hibernate cannot unwrap Cache as '{type.getName()}'\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Second-level caching is misconfigured or a cache region/key does not match what Hibernate expects.","commonSituations":"Enabling @Cacheable entities without setting hibernate.cache.region.factory_class, custom RegionFactory implementations, or unwrapping Cache to provider types.","solutions":["Unwrap the Cache to a type it actually implements (e.g. the provider's region type), or check that the expected cache provider is configured."],"exampleFix":"Unwrap the Cache to a type it actually implements (e.g. the provider's region type), or check that the expected cache provider is configured.","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"}