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).

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 throws IllegalArgumentException
Instead of returning {{null}.

Activity

Show:

Former userMay 8, 2018 at 12:27 AM

Fixed in 5.1 branch as well.

Steve EbersoleApril 26, 2018 at 5:41 PM

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.

Fixed

Details

Assignee

Reporter

Components

Affects versions

Priority

Created April 19, 2018 at 11:39 PM
Updated May 8, 2018 at 12:28 AM
Resolved May 8, 2018 at 12:27 AM