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

Environment

None

Activity

Show:
Gail Badner
April 20, 2018, 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.

Gail Badner
April 25, 2018, 7:55 PM

The NPE bugfix for 5.2/5.1 will be covered by

Gail Badner
April 25, 2018, 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.

Steve Ebersole
April 26, 2018, 5:41 PM

Considering they are completely different issues, that seems reasonable

Gail Badner
May 8, 2018, 12:27 AM

Fixed in 5.1 branch as well.

Assignee

Gail Badner

Reporter

Gail Badner

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure