{"record":{"id":"1027d66579db46ad","repo":"quarkusio/quarkus","slug":"cache-for-region-s-not-found","errorCode":null,"errorMessage":"Cache for region %s not found","messagePattern":"Cache for region (.+?) not found","errorType":"exception","errorClass":"IllegalStateException","httpStatus":500,"severity":"error","filePath":"integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java","lineNumber":100,"sourceCode":"                .orElse(\"not-set\");\n    }\n\n    @GET\n    @Produces(MediaType.TEXT_PLAIN)\n    @Path(\"/has-weigher/{region}\")\n    public String hasWeigher(@PathParam(\"region\") String region) {\n        CaffeineConfiguration<?, ?> config = getCacheConfig(region);\n        return String.valueOf(config.getWeigherFactory().isPresent());\n    }\n\n    private Cache<?, ?> getRegionCache(String region) {\n        var sessionFactory = emf.unwrap(SessionFactory.class);\n        var cache = (CacheImplementor) sessionFactory.getCache();\n        var regionFactory = (JCacheRegionFactory) cache.getRegionFactory();\n        var cacheManager = regionFactory.getCacheManager();\n        Cache<?, ?> regionCache = cacheManager.getCache(region);\n        if (regionCache == null) {\n            throw new IllegalStateException(String.format(\"Cache for region %s not found\", region));\n        }\n        return regionCache;\n    }\n\n    private CaffeineConfiguration<?, ?> getCacheConfig(String region) {\n        return getRegionCache(region).getConfiguration(CaffeineConfiguration.class);\n    }\n\n    /**\n     * Lists the various operations we want to test for:\n     */\n    private void doStuffWithHibernate() {\n        //Cleanup any existing data:\n        deleteAll();\n\n        testReadOnly();\n        testReadWrite();\n        testNonStrictReadWrite();","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/hibernate-orm-cache/src/main/java/io/quarkus/it/hibernate/orm/cache/HibernateOrmCacheTestEndpoint.java#L82-L118","documentation":"This endpoint method unwraps the Hibernate SessionFactory cache, obtains the JCacheRegionFactory's CacheManager, and looks up the JCache for a given second-level-cache region name. If the CacheManager has no cache registered under that region name, it throws this IllegalStateException. It signals that the requested Hibernate cache region was never created — typically because no entity/collection/query is configured to use that region.","triggerScenarios":"GET to the test endpoint with a region name (entity or collection region, e.g. an entity class FQCN or collection role) that has no corresponding @Cacheable/@Cache mapping or is not present in quarkus.hibernate-orm.cache.* configuration, so JCacheRegionFactory never created that cache.","commonSituations":"Typo in region name passed as query param; entity missing @Cache annotation or quarkus.hibernate-orm second-level cache config removed; cache region not yet initialized because no access touched it; switching cache backends (e.g. from Caffeine to Infinispan) where region naming differs.","solutions":["Verify the region name matches the entity FQCN or collection role exactly (case-sensitive)","Ensure the entity/collection is annotated with @Cache or configured via quarkus.hibernate-orm cache properties so the region is created","Access the cached entity/collection once before querying statistics so the region is initialized","Check the configured cache backend supports/creates the expected regions"],"exampleFix":"// before\ncacheManager.getCache(region); // null for 'com.example.Item' if Item has no @Cache\n// after\n@Entity\n@Cacheable\n@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = \"com.example.Item\")\npublic class Item { ... }","handlingStrategy":"validation","validationCode":"Cache<?, ?> regionCache = regionFactory.getCacheManager().getCache(region);\nif (regionCache == null) {\n    throw new ResponseStatusException(404, \"Unknown cache region: \" + region + \"; check @Cache mappings and quarkus.hibernate-orm cache config\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Cache<?, ?> c = getRegionCache(region);\n} catch (IllegalStateException e) {\n    // fall back: list available regions\n    Set<String> known = cache.getCacheNames();\n    throw new IllegalArgumentException(\"Region '\" + region + \"' not found; known: \" + known);\n}","preventionTips":["Keep region names generated from entity FQCNs, never hand-typed","Annotate entities/collections with @Cache so regions exist before queries","Touch each cached region once at startup to force initialization"],"tags":["hibernate","jcache","second-level-cache","quarkus","cache-region"],"backgroundTag":"cache-region-not-found","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}