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

Status

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

5.1.13
5.2.15
5.2.16

Priority

Major