org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory cannot be cast to org.hibernate.cache.spi.RegionFactory

Hello,

Am currently working on a legacy application and am trying to deploy it in Wildfly 13.0.0. It uses hibernate 4.2.0 and when starting the application i receive the error message specified in the title (org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory cannot be cast to org.hibernate.cache.spi.RegionFactory). I had included org.hibernate.hibernate-ehcache (v4.2.0) in my maven dependencies, and also org.ehcache.ehcache (v3.2).

	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-entitymanager</artifactId>
		<version>4.2.0.Final</version>
	</dependency>
	<dependency>
		<groupId>org.hibernate</groupId>
		<artifactId>hibernate-ehcache</artifactId>
		<version>4.2.0.Final</version>
	</dependency>
	<dependency>
		<groupId>org.ehcache</groupId>
		<artifactId>ehcache</artifactId>
		<version>3.2</version>
	</dependency>

and have added the following properties in persistence.xml

<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />

I did try to upgrade the version of hibernate to 5.4.21.Final, however, receiving the same error and hence my suspicion is the issue doesn’t have anything to do with version of hibernate. Did try to Google it and most of the results points to a issue when we upgrade hibernate from 3.x to 4.x where we must use org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory instead of
net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory, however, this case shouldn’t be applicable to me as am already using hibernate 4.x and org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory.

Can someone point to the correct root cause of the issue ?

Regards,
Sreram

My bad.

I were adding the dependencies on the parent project, while the child project was giving the exception and the child project didn’t have the hibernate-ehcache dependency.

The issue is resolved now.

Thanks.