{"record":{"id":"b92e8c327a30e43a","repo":"hibernate/hibernate-orm","slug":"not-an-instance-of-cachekeyimplementation-cachekey","errorCode":null,"errorMessage":"Not an instance of CacheKeyImplementation{cacheKeyObject}","messagePattern":"Not an instance of CacheKeyImplementation(.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeysFactory.java","lineNumber":105,"sourceCode":"\n\t@Nonnull\n\tpublic static Object staticCreateNaturalIdKey(\n\t\t\t@Nonnull Object naturalIdValues,\n\t\t\t@Nonnull EntityPersister persister,\n\t\t\t@Nonnull SharedSessionContractImplementor session) {\n\t\treturn NaturalIdCacheKey.from( naturalIdValues, persister, session );\n\t}\n\n\t@Nonnull\n\tpublic static Object staticGetEntityId(@Nonnull Object cacheKeyObject) {\n\t\tif ( cacheKeyObject instanceof BasicCacheKeyImplementation basicCacheKey ) {\n\t\t\treturn basicCacheKey.id;\n\t\t}\n\t\telse if ( cacheKeyObject instanceof CacheKeyImplementation cacheKey) {\n\t\t\treturn cacheKey.getId();\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalArgumentException( \"Not an instance of CacheKeyImplementation\" + cacheKeyObject );\n\t\t}\n\t}\n\n\t@Nonnull\n\tpublic static Object staticGetCollectionId(@Nonnull Object cacheKey) {\n\t\treturn staticGetEntityId( cacheKey );\n\t}\n\n\t@Nonnull\n\tpublic static Object staticGetNaturalIdValues(@Nonnull Object cacheKey) {\n\t\treturn ( (NaturalIdCacheKey) cacheKey ).getNaturalIdValues();\n\t}\n\n\t@Override\n\t@Nonnull\n\tpublic Object createCollectionKey(\n\t\t\t@Nonnull Object id,\n\t\t\t@Nonnull CollectionPersister persister,","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/cache/internal/DefaultCacheKeysFactory.java#L87-L123","documentation":"Error \"Not an instance of CacheKeyImplementation{cacheKeyObject}\" 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":["Do not pass arbitrary objects as cache keys; use the keys produced by the Session/Cache API (CacheKeyImplementation instances)."],"exampleFix":"Do not pass arbitrary objects as cache keys; use the keys produced by the Session/Cache API (CacheKeyImplementation instances).","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"}