hibernate/hibernate-orm · error · IllegalArgumentException
Region name [{}] referred to a query result region, not a do
Error message
Region name [{}] referred to a query result region, not a domain data region What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/stat/internal/StatisticsImpl.java:1018
private CollectionStatisticsImpl instantiateCollectionStatistics(final String role) {
return new CollectionStatisticsImpl( metamodel.getCollectionDescriptor( role ) );
}
private NaturalIdStatisticsImpl instantiateNaturalStatistics(final String entityName) {
final EntityPersister entityDescriptor = metamodel.getEntityDescriptor( entityName );
if ( !entityDescriptor.hasNaturalIdentifier() ) {
throw new IllegalArgumentException( "Given entity [" + entityName + "] does not define natural-id" );
}
return new NaturalIdStatisticsImpl( entityDescriptor );
}
private CacheRegionStatisticsImpl instantiateCacheRegionStatistics(final String regionName) {
final Region region = cache.getRegion( regionName );
if ( region == null ) {
throw new IllegalArgumentException( "Unknown cache region : " + regionName );
}
if ( region instanceof QueryResultsRegion ) {
throw new IllegalArgumentException(
"Region name [" + regionName + "] referred to a query result region, not a domain data region"
);
}
return new CacheRegionStatisticsImpl( region );
}
private CacheRegionStatisticsImpl instantiateCacheRegionStatsForQueryResults(final String regionName) {
return new CacheRegionStatisticsImpl( cache.getQueryResultsCache( regionName ).getRegion() );
}
private @Nullable CacheRegionStatisticsImpl createCacheRegionStatistics(final String regionName) {
Region region = cache.getRegion( regionName );
if ( region == null ) {
if ( !queryCacheEnabled ) {
return null;
}
// this is the pre-5.3 behavior. and since this is a pre-5.3 method it should behave consistently
// NOTE that this method is deprecatedView on GitHub (pinned to fad1729dce)
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.
Example fix
// before
CacheRegionStatistics s = statistics.getDomainDataRegionStatistics("default-query-results-region");
// IllegalArgumentException: query result region
// after
CacheRegionStatistics s = statistics.getQueryRegionStatistics("default-query-results-region"); Defensive patterns
Strategy: validation
Validate before calling
Set<String> queryRegions = Set.of("default-query-results-region"); // + any named query caches
CacheRegionStatistics s = queryRegions.contains(regionName)
? statistics.getQueryRegionStatistics(regionName)
: statistics.getDomainDataRegionStatistics(regionName); Try / catch
try {
s = statistics.getDomainDataRegionStatistics(regionName);
} catch (IllegalArgumentException e) {
// may be a query-result region — retry via the query path
s = statistics.getQueryRegionStatistics(regionName);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unknown cache region : {}
- immutable global instance of LockOptions
- Custom event-type name must be non-null.
- Unknown query type for registering as named query (%s) : %s
- Hibernate cannot unwrap EntityManagerFactory as '{type.getNa
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/b8fa506e16aea0c3.
Report an issue: GitHub.