Misleading error message is shown when no RegionFactory is manually set

Description

When an entity is marked as @Cacheable (and have @Cache on it, to work around HHH-7101), an exception will be thrown when calling Persistence.createEntityManagerFactory(String) informing the user that cache is not enabled and either hibernate.cache.use_second_level_cache or hibernate.cache.use_query_cache need to be set.

Although this is obviously very helpful, the exception will continue to be thrown with the same text even once both properties are set to true:

Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
at org.hibernate.cache.internal.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:69)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:347)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1740)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:88)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
... 11 more

At this point, the problem is Hibernate is using NoCachingRegionFactory instead of a valid one, but the message is completely deceiving and wastes user time. Instead, a clear message showing that a RegionFactory other than NoCachingRegionFactory should be set using hibernate.cache.region.factory_class should be produced instead.

Attached is a Maven-powered sample with Derby that can be executed with exec:java .

Environment

hibernate-jpa-2.0-api:1.0.1.Final; hibernate-core:4.1.0.Final; hibernate-entitymanager:4.1.0.Final

Status

Assignee

Strong Liu

Reporter

Michael Nascimento Santos

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure