Statistics # getSecondLevelCacheRegionNames returns names for query caches as well

The doc comment to Statistics#getSecondLevelCacheRegionNames() says that for backwards compatibility, this method returns just the names of regions storing domain data, not query result cache regions.

Maybe I’m missing something, but using this method returns the cache names for my query caches as well. I have an Ehcache 3 which I configure like that:

<cache-template name="small-cache">
        <offheap unit="MB">1</offheap>

<cache alias="email-status-cache" uses-template="small-cache"/>
<cache alias="email-status-query-cache" uses-template="small-cache"/>

Well, the Ehcache configuration says nothing about the use case of the configured caches. So I assume that Hibernate will derive the use case from the placing of the case specific annotations. For classic entity caches eg. @org.hibernate.annotations.Cache(region = "email-status-cache", usage = CacheConcurrencyStrategy.READ_ONLY).

And for query caches:

@QueryHints(value = {
    @QueryHint(name = HibernateHints.HINT_CACHEABLE, value = "true"),
    @QueryHint(name = HibernateHints.HINT_CACHE_REGION, value = "email-status-query-cache")
}, forCounting = false)

Surprisingly, when calling Statistics#getSecondLevelCacheRegionNames(), both cache region names get delivered, meaning the query cache region name will be returned as well.

Is this a bug, a feature or am I just missing anything? Can I rely on this beahvior in future as well?

Many thanks for any information

It looks like a documentation bug. This behavior was changed as part of [HHH-15114] - Hibernate JIRA. Please create a JIRA issue for this and a PR to remove the part about backwards compatibility reasons.

Thanks for the information, I’ve created an issue [HHH-17452] - Hibernate JIRA

1 Like