{"record":{"id":"b8fa506e16aea0c3","repo":"hibernate/hibernate-orm","slug":"region-name-referred-to-a-query-result-region","errorCode":null,"errorMessage":"Region name [{}] referred to a query result region, not a domain data region","messagePattern":"Region name \\[(.+?)\\] referred to a query result region, not a domain data region","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java","lineNumber":1018,"sourceCode":"\tprivate CollectionStatisticsImpl instantiateCollectionStatistics(final String role) {\n\t\treturn new CollectionStatisticsImpl( metamodel.getCollectionDescriptor( role ) );\n\t}\n\n\tprivate NaturalIdStatisticsImpl instantiateNaturalStatistics(final String entityName) {\n\t\tfinal EntityPersister entityDescriptor = metamodel.getEntityDescriptor( entityName );\n\t\tif ( !entityDescriptor.hasNaturalIdentifier() ) {\n\t\t\tthrow new IllegalArgumentException( \"Given entity [\" + entityName + \"] does not define natural-id\" );\n\t\t}\n\t\treturn new NaturalIdStatisticsImpl( entityDescriptor );\n\t}\n\n\tprivate CacheRegionStatisticsImpl instantiateCacheRegionStatistics(final String regionName) {\n\t\tfinal Region region = cache.getRegion( regionName );\n\t\tif ( region == null ) {\n\t\t\tthrow new IllegalArgumentException( \"Unknown cache region : \" + regionName );\n\t\t}\n\t\tif ( region instanceof QueryResultsRegion ) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"Region name [\" + regionName + \"] referred to a query result region, not a domain data region\"\n\t\t\t);\n\t\t}\n\t\treturn new CacheRegionStatisticsImpl( region );\n\t}\n\n\tprivate CacheRegionStatisticsImpl instantiateCacheRegionStatsForQueryResults(final String regionName) {\n\t\treturn new CacheRegionStatisticsImpl( cache.getQueryResultsCache( regionName ).getRegion() );\n\t}\n\n\tprivate @Nullable CacheRegionStatisticsImpl createCacheRegionStatistics(final String regionName) {\n\t\tRegion region = cache.getRegion( regionName );\n\t\tif ( region == null ) {\n\t\t\tif ( !queryCacheEnabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t// this is the pre-5.3 behavior.  and since this is a pre-5.3 method it should behave consistently\n\t\t\t// NOTE that this method is deprecated","sourceCodeStart":1000,"sourceCodeEnd":1036,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java#L1000-L1036","documentation":"The statistics API splits cache regions into domain-data regions (entity/collection data) and query-result regions. instantiateCacheRegionStatistics looks the name up and, when the Region is a QueryResultsRegion, refuses it with an IllegalArgumentException — query-result region counters must be read through the query-results path (instantiateCacheRegionStatsForQueryResults), which backs Statistics#getQueryRegionStatistics.","triggerScenarios":"Passing a query-results region name (the default query results region, e.g. default-query-results-region, or a named query cache's region) to getDomainDataRegionStatistics; the instanceof QueryResultsRegion check fires and the call is rejected as a wrong region kind.","commonSituations":"A dashboard iterates every name from getSecondLevelCacheRegionNames() and routes them all into the domain-data accessor; entity-cache and query-cache names mixed in one configuration list; copy-pasting the domain call for the query cache.","solutions":["Call statistics.getQueryRegionStatistics(regionName) for query-result regions; keep getDomainDataRegionStatistics for entity/collection regions.","Route by name: keep query-cache region names (default-query-results-region and any named query caches) in a separate list and dispatch to the query API."],"exampleFix":"// before\nCacheRegionStatistics s = statistics.getDomainDataRegionStatistics(\"default-query-results-region\");\n// IllegalArgumentException: query result region\n\n// after\nCacheRegionStatistics s = statistics.getQueryRegionStatistics(\"default-query-results-region\");","handlingStrategy":"validation","validationCode":"Set<String> queryRegions = Set.of(\"default-query-results-region\"); // + any named query caches\nCacheRegionStatistics s = queryRegions.contains(regionName)\n        ? statistics.getQueryRegionStatistics(regionName)\n        : statistics.getDomainDataRegionStatistics(regionName);","typeGuard":null,"tryCatchPattern":"try {\n    s = statistics.getDomainDataRegionStatistics(regionName);\n} catch (IllegalArgumentException e) {\n    // may be a query-result region — retry via the query path\n    s = statistics.getQueryRegionStatistics(regionName);\n}","preventionTips":["Treat domain-data and query-result regions as separate lists in monitoring config.","Name explicit regions with @Cache(region=...) and named query caches so kinds are obvious.","Never feed an unfiltered getSecondLevelCacheRegionNames() list into the domain-data accessor."],"tags":["hibernate","query-cache","statistics","cache-region","api-misuse"],"backgroundTag":"wrong-cache-region-type","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}