SessionFactoryOptions#isSecondLevelCacheEnabled returns true by default with NoCachingRegionFactory
Description
When caching is not explicitly enabled or disabled via hibernate.cache.query_cache_factory, SessionFactoryOptionsBuilder#secondLevelCacheEnabled will be set to true by default.
As a result, SessionFactory#getSessionFactoryOptions()#isSecondLevelCacheEnabled() will return true, even in cases where NoCachingRegionFactory is the RegionFactory (due to other cache-related settings).
For example, when debugging StatisticsImpl#getCacheRegionStatistics, I see that sessionFactory.getSessionFactoryOptions().isSecondLevelCacheEnabled() incorrectly returns true, when NoCachingRegionFactory is used.
As a result, StatisticsImpl#getCacheRegionStatistics throws IllegalArgumentException Instead of returning {{null}.
Considering they are completely different issues, that seems reasonable
Former userApril 25, 2018 at 8:18 PM
, this issue can be resolved as fixed if a different issue is opened to cover StatisticsImpl#getCacheRegionStatistics throwing an exception if 2nd-level cache is enabled, but the region does not exist.
Former userApril 25, 2018 at 7:55 PM
The NPE bugfix for 5.2/5.1 will be covered by
Former userApril 20, 2018 at 6:28 AM
Edited
Javadoc for Statistics#getCacheRegionStatistics says:
@return Stats for the named region, or {@code null} if no such region exists
In master (5.3) only, StatisticsImpl#getCacheRegionStatistics throws an exception if 2nd-level cache is enabled, but the region does not exist.
This still needs to be fixed, as an exception is thrown if the second-level cache is enabled, but the query cache is disabled.
When caching is not explicitly enabled or disabled via
hibernate.cache.query_cache_factory
,SessionFactoryOptionsBuilder#secondLevelCacheEnabled
will be set totrue
by default.As a result,
SessionFactory#getSessionFactoryOptions()#isSecondLevelCacheEnabled()
will returntrue
, even in cases whereNoCachingRegionFactory
is theRegionFactory
(due to other cache-related settings).This inconsistency can cause problems such as https://issues.jboss.org/browse/WFLY-10260.
For example, when debugging StatisticsImpl#getCacheRegionStatistics, I see that sessionFactory.getSessionFactoryOptions().isSecondLevelCacheEnabled() incorrectly returns true, when
NoCachingRegionFactory
is used.As a result,
StatisticsImpl#getCacheRegionStatistics
throwsIllegalArgumentException
Instead of returning {{null}.